dfsgwe 发表于 2016-4-8 14:16:28

ansible playbook循环

Ansible playbook中的循环

vim /etc/ansible/loop.yml
---
- hosts: testhost
user: root
tasks:
    - name: change mode for files
      file: path=/tmp/{{ item }} mode=600 owner=root group=root
      with_items:
      - 1.txt
      - 2.txt
      - 3.txt

执行命令:ansible-playbook loop.yml
说明:item相当于shell中的循环变量,固定写法,使用file模块来调用循环变量
执行结果为,改变/tmp/1.txt /tmp/2.txt /tmp/3.txt的权限,如果文件不存在,则报错。

CO-OP 发表于 2016-4-9 22:45:16

学习方法
页: [1]
查看完整版本: ansible playbook循环