永不落伍 发表于 2018-7-30 10:05:31

3.8-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的权限,如果文件不存在,则报错。
页: [1]
查看完整版本: 3.8-ansible playbook循环