首页 > 其他 > 详细

with_items标准循环

时间:2019-02-23 15:59:39      阅读:187      评论:0      收藏:0      [点我收藏+]

1.为不同用户定义不同组

---
- hosts: web2
  remote_user: root
  tasks:
    - user:
        name: "{{item.name}}"
        group: "{{item.group}}"
        password: "{{‘123456‘|password_hash(‘sha512‘)}}"
      with_items:
        - {name: "aa", group: "users"}
        - {name: "bb", group: "mail" }
        - {name: "cc", group: "wheel"}
        - {name: "dd", group: "root" }

运行

#  ansible-playbook add.yml

注意item.name 中间是点,组是自己存在的

 

 2.嵌套循环,循环添加多用户

---
- hosts: web2
  remote_user: root
  vars:
    un: [a, b, c]
    id: [1, 2, 3]
  tasks:
    - name: add users
      shell: echo {{item}}
      with_nested:
        - "{{un}}"
        - "{{id}}"

 

with_items标准循环

原文:https://www.cnblogs.com/lsgo/p/10422959.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!