ansible迭代循环集合

时间:2017-02-07 19:28:36

标签: ansible ansible-2.x

执行ansible-playbook -i "localhost," -c local main.yml时,输出为

ok: [localhost] => (item=users) => {
    "item": "users",
    "msg": "use

但我宁愿迭代这些元素。如何实现这一目标?

这是我的最小例子:

main.yml

---
- hosts: all
  tasks:
    - debug: msg={{ item }}
      #include_vars: users.yml
      with_items: users

users.yml里

---
users:
  - username: test_user
    password: test_user
    sn: User
    uid: 50001
    gid: 100
  - username: test_user1
    password: test_user
    cn: Test User1
    sn: User1
    uid: 50002
    gid: 100

user_groups:
  - cn: access1
    gid: 100001
    users:
      - test_user1

1 个答案:

答案 0 :(得分:1)

这是正确的语法:

---
- hosts: all
  tasks:
    - include_vars: users.yml
    - debug: msg={{ item }}
      with_items: "{{ users }}"