var 为变量
item是循环变量
下面任务为新增两个用户testuser1,testuser2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[root@ES25 zfl]# cat useradd01.yml
---
- hosts: 10.4.104.85
tasks:
############方法1
-name: add user testuser1
user: name=testuser1 state=present groups=wheel
-name: add user testuser2
user: name=testuser2 state=present groups=wheel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[root@ES25zfl]# cat useradd02.yml
---
- hosts: 10.4.104.85
vars:
user1: testuser1
user2: testuser2
tasks:
#############方法2
-name: add several users
user: name=` user1 ` state=present groups=wheel
-name: add several users
user: name=` user2 ` state=present groups=wheel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
利用with_items