循环添加linux用户

循环添加linux用户

   张吉吉     2019年11月29日 00:44     1746    

1、今天需要给3个服务器添加三个用户,当然可以用很麻烦的办法一个一个去添加,但是这个是非常消耗时间的,所以准备用ansible的脚本去添加。

添加服务器

1.png

 

(1)不使用循环的脚本

---

- hosts: test

  tasks:

  - name: add user1

    user: name="user1" password={{ "123456" | password_hash('sha512') }}  state="present"

  - name: add user2

    user: name="user2" password={{ "123456" | password_hash('sha512') }}  state="present"

  - name: add user3

user: name="user3" password={{ "123456" | password_hash('sha512') }}  state="present"

执行脚本

查看结果,下边是其中一个服务器的用户列表

2.png

(2)使用循环脚本

---

- hosts: test

  tasks:

  - name: add user1,user2,user3

    user: name={{ item }} password={{ "123456" | password_hash('sha512') }}  state="present"

    with_items:

     - user1

     - user2

     - user3

执行

3.png


文章评论

0

其他文章