1、直接循环创建
1、编写最基本的yml文件,直接循环创建
[root@server4 ~]# su - devopes
[devopes@server4 ~]$ cd ansible/
[devopes@server4 ansible]$ ls
ansible.cfg apache.yml files inventory playbook.yml roles templates
[devopes@server4 ansible]$ vim createuser.yml
---
- hosts: test
tasks:
- name: create user
user:
name: "{
{ item.user }}"
password: "{
{ item.pass| password_hash('sha512') }}"
state: present
loop:
- { user: user1, pass: 12345678a }
- { user: user2, pass: 12345678a }
- { user: user3, pass: 12345678a }
2、查看inventory文件
[devopes@server4 ansible]$ vim inventory
[devopes@server4 ansible]$ cat inventory
[lb]
server4 STATE=MASTER VRID=100 PRIORITY=100
server7 STATE=BACKUP VRID=100 PRIORITY=50
[test]
server5
[prod]
server6
[webserver:children]
test