主机列表: 192.168.110.1 ....... 192.198.110.10。
您需要在每个用户上创建一个用户: 鲍勃 ... 爱丽丝
我想在一个剧本中实现它,以免每个主机运行10次。
用户创建类似这样的内容:
vars_prompt:
- name: "user_name"
prompt: "User name"
private: no
- name: "user_password"
prompt: "Enter a password for the user"
private: yes
encrypt: "md5_crypt"
confirm: yes
salt_size: 7
tasks:
- name: "add new user"
user:
name: "{{user_name}}"
password: "{{user_password}}"
shell: /bin/bash
答案 0 :(得分:1)
您可以在inventory
文件中添加不同的主机组:
[alice_hosts]
192.168.110.2
[bob_hosts]
192.168.110.1
然后仅在以下特定组上的playbook.yml
中运行一些命令:
- hosts: all
tasks:
# Do some common stuff
- hosts: alice_hosts
tasks:
- name: "add new user"
user:
name: alice
password: alice_password
shell: /bin/bash
- hosts: bob_hosts
tasks:
- name: "add new user"
user:
name: bob
password: bob_password
shell: /bin/bash