1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| - hosts: 192.168.8.32 tasks: - name: create{{ user }} user: name={{ user }}
#方式一 -e ansible-playbook -e 'user=ropon02' p2.yml #检查是否创建成功 ansible 192.168.8.32 -m shell -a 'id ropon02'
#方式二 主机后面 指定参数 192.168.8.32 user=ropon03 ansible-playbook p2.yml #检查是否创建成功 ansible 192.168.8.32 -m shell -a 'id ropon03'
#方式三 主机组[:vars] 组后面指定参数(新起一行写与之前的主机名) [web:vars] user=ropon04
cat p3.pml - hosts: web tasks: - name: create{{ user }} user: name={{ user }}
ansible-playbook p3.yml #检查是否创建成功 ansible web -m shell -a 'id ropon04'
#方式四 yml文件vars指定参数 cat p3.pml - hosts: web vars: - user: ropon05 tasks: - name: create{{ user }} user: name={{ user }}
ansible-playbook p4.yml #检查是否创建成功 ansible web -m shell -a 'id ropon05'
#方式五 register cat p5.yml - hosts: web tasks: - name: sum shell: echo 3+3bc register: user - name: createropon06 user: name=ropon0{{user.stdout}}
ansible-playbook p5.yml
#参数优先级 -e > playbook vars > 主机hosts文件
|