可靠的策略:创建一个多个用户名,但我有一个问题


- name: Create a many dev and ops account in managed 1
hosts: pod-jesayafernando9-managed1
become: true
tasks:
- name: Create dev[1-50] in managed 1
ansible.builtin.user:
name: "{{item}}"
password: adinusa88
state: present
loop: dev[1:50]
- name: Create ops[1-50] in managed 1
ansible.builtin.user:
name: "{{item}}"
password: adinusa88
state: present
loop: ops[1:50]
- name: Create a many dev and ops account in managed 2
hosts: pod-jesayafernando9-managed2
become: true
tasks:
- name: Create dev[51-100] in managed 2
ansible.builtin.user:
name: "{{item}}"
password: adinusa88
state: present
loop: dev[51:100]
- name: Create ops[51-100] in managed 2
ansible.builtin.user:
name: "{{item}}"
password: adinusa88
state: present
loop: ops[51:100]

如何使用户名dev1…dev100或ops1…ops100?我试着用with_sequence,但当它达到10时,就会出现字母表而不是数字。

with_sequence使用以下方式正常工作,我在计算机上创建了一个从ops1到ops50的小示例。我看到的唯一问题是表演,它有点慢。

---
- hosts: dev
tasks:
- name: create users
user:
name: ops{{item}}
password: "{{'test' | password_hash('sha512')}}"
state: present
with_sequence: start=1 end=50

正如官方可解释的文件所说:可解释的WITH_SEQUENCE DOCwith_sequence以这种方式替换为循环:

---
- hosts: dev
tasks:
- name: create users
user:
name: ops{{item}}
password: "{{'test' | password_hash('sha512')}}"
state: present
loop: "{{range(1,50)| list}}"

我建议使用这个,因为它是可靠的官方文件所说的,

相关内容

  • 没有找到相关文章

最新更新