自动化-ansible-playbook循环
host1:192.168.2.251
1:编写修改1.txt、2.txt属性循环文件
[root@ghs ansible]# vim for.yml
---
- hosts: 192.168.2.252
user: root
tasks:
- name: change mod for file
file: path=/tmp/{{ item }} mode=600
with_items:
- 1.txt
- 2.txt
{{ item }}:固定循环写法,调用的是 with_items下的文件循环
2:运行for.yml循环文件
[root@ghs ansible]# ansible-playbook for.yml
PLAY [192.168.2.252] ****************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************
ok: [192.168.2.252]
TASK [change mod for file] **********************************************************************************************
changed: [192.168.2.252] => (item=1.txt)
changed: [192.168.2.252] => (item=2.txt)
PLAY RECAP **************************************************************************************************************
192.168.2.252 : ok=2 changed=1 unreachable=0 failed=0
host2:192.168.2.252
3:查看1.txt、2.txt权限
原
[root@ghs2 ~]# ls -l /tmp/
总用量 0
-rw-r--r--. 1 root root 0 7月 22 06:34 1.txt
-rw-r--r--. 1 root root 0 7月 22 06:34 2.txt
更改后
[root@ghs2 ~]# ls -l /tmp/
总用量 0
-rw-------. 1 root root 0 7月 22 06:34 1.txt
-rw-------. 1 root root 0 7月 22 06:34 2.txt
记录每一天有趣的事情!!

浙公网安备 33010602011771号