ansible切换目录

1、ansible切换目录并且创建文件

1.1、使用shell模块操作

[root@master ~]# ansible k8s -m shell -a "chdir=/rubbish touch test.conf"

1.2、使用command操作

[root@master ~]# ansible k8s -m command -a "chdir=/rubbish touch test.conf"

 2、replace模块(查找替换)

ansible master -m replace -a "path=/etc/systemd/system/etcd.service regexp='master=' replace='$ECTD_CLUSTER' backup=yes"

path参数 :必须参数,指定要操作的文件

regexp参数 : 必须参数,指定一个 python 正则表达式,文件中与正则匹配的字符串将会被替换

replace参数 : 指定最终要替换成的字符串

backup参数 :是否在修改文件之前对文件进行备份,最好设置为yes

猜你喜欢

转载自www.cnblogs.com/effortsing/p/10289796.html