Linux自动化工具之Ansible playbook循环
2020-02-21自动化运维90root382°c
A+ A-1、新建测试文件
[[email protected] ~]# cd /etc/ansible/ [[email protected] ansible]# vim loop.yml 1 --- 2 - hosts: testhosts 3 user: root 4 tasks: 5 - name: change mode for files 6 file: path=/tmp/{{ item }} mode=600 owner=root group=root 7 with_items: 8 - 4.txt 9 - 5.txt
2、创建文件,两台机器都创建
[[email protected] ansible]# touch /tmp/{4.txt,5.txt} [[email protected] ~]# touch /tmp/{4.txt,5.txt}
3、执行配置文件
[[email protected] ansible]# ansible-playbook loop.yml PLAY [testhosts] *************************************************************** TASK [setup] ******************************************************************* ok: [101.200.148.30] ok: [127.0.0.1] TASK [change mode for files] *************************************************** changed: [101.200.148.30] => (item=4.txt) ok: [127.0.0.1] => (item=4.txt) changed: [101.200.148.30] => (item=5.txt) ok: [127.0.0.1] => (item=5.txt) PLAY RECAP ********************************************************************* 101.200.148.30 : ok=2 changed=1 unreachable=0 failed=0 127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0
4、查看权限是不是改好了
[[email protected] ~]# ls -l /tmp/ total 20 -rw-r--r-- 1 root root 1099 Jul 16 04:26 123 drwxr-xr-x 3 root root 4096 Jul 16 04:45 456 -rw------- 1 root root 0 Jul 17 12:09 4.txt -rw------- 1 root root 0 Jul 17 12:09 5.txt srwxrwxrwx 1 root root 0 Jul 15 23:23 Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)> drwxr-xr-x 3 root root 4096 Jul 16 04:44 ansibletestowner=root -rw-r--r-- 1 root root 29 Jul 16 05:03 ansible_test.txt -rw-r--r-- 1 root root 0 Jul 17 00:57 playbook2.txt -rw-r--r-- 1 root root 0 Jul 17 01:08 playbook.txt srwxrwxrwx 1 root root 0 Jul 15 23:23 qtsingleapp-aegisG-46d2 srwxrwxrwx 1 root root 0 Apr 21 21:08 qtsingleapp-aegiss-a5d2 -rwxr-xr-x 1 root root 46 Jul 16 05:01 test.sh
注意:可看到权限为 600,主和组都为root。