[root@ansible ~]# ansible webservers -m user -a 'state=present name=yun password=123456 uid=1200 group=root'
^[[D[WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly.
192.168.92.20 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"append": false,
"changed": true,
"comment": "",
"group": 0,
"home": "/home/yun",
"move_home": false,
"name": "yun",
"password": "NOT_LOGGING_PASSWORD",
"shell": "/bin/bash",
"state": "present",
"uid": 1200
}
[root@ansible ~]# ansible webservers -m user -a 'state=absent name=yun'
192.168.92.20 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": true,
"force": false,
"name": "yun",
"remove": false,
"state": "absent",
"stderr": "userdel: group yun not removed because it is not the primary group of user yun.\n",
"stderr_lines": [
"userdel: group yun not removed because it is not the primary group of user yun."
]
}
[root@ansible ~]# ansible webservers -m group -a 'name=yun2 state=present'
192.168.92.20 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": true,
"gid": 1001,
"name": "yun2",
"state": "present",
"system": false
}
[root@ansible ~]# ansible webservers -m user -a 'state=present name=yun password=123456 uid=1200 group=root groups=yun2'
[WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly.
192.168.92.20 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 0,
"groups": "yun2",
"home": "/home/yun",
"name": "yun",
"password": "NOT_LOGGING_PASSWORD",
"shell": "/bin/bash",
"state": "present",
"stderr": "useradd: warning: the home directory /home/yun already exists.\nuseradd: Not copying any file from skel directory into it.\nCreating mailbox file: File exists\n",
"stderr_lines": [
"useradd: warning: the home directory /home/yun already exists.",
"useradd: Not copying any file from skel directory into it.",
"Creating mailbox file: File exists"
],
"system": false,
"uid": 1200
}
[root@ansible ~]# ansible webservers -m user -a 'name=yun2 state=present password=123456 group=root groups=root,yun2'
[WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly.
192.168.92.20 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 0,
"groups": "root,yun2",
"home": "/home/yun2",
"name": "yun2",
"password": "NOT_LOGGING_PASSWORD",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1201
}
[root@ansible ~]# ansible webservers -m user -a 'name=yun2 state=absent'
192.168.92.20 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": true,
"force": false,
"name": "yun2",
"remove": false,
"state": "absent",
"stderr": "userdel: group yun2 not removed because it is not the primary group of user yun2.\n",
"stderr_lines": [
"userdel: group yun2 not removed because it is not the primary group of user yun2."
]
}
[root@ansible ~]# ansible webservers -m shell -a 'ls /home'
192.168.92.20 | CHANGED | rc=0 >>
yun
yun2
[root@ansible ~]# ansible webservers -m user -a 'name=yun remove=yes state=absent'
192.168.92.20 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": true,
"force": false,
"name": "yun",
"remove": true,
"state": "absent",
"stderr": "userdel: group yun not removed because it is not the primary group of user yun.\n",
"stderr_lines": [
"userdel: group yun not removed because it is not the primary group of user yun."
]
}
[root@ansible ~]# ansible webservers -m shell -a 'ls /home'
192.168.92.20 | CHANGED | rc=0 >>
yun2
[root@ansible ~]# ansible webservers -m user -a 'state=present name=yun password=123456 uid=1200 group=root groups=yun2 generate_ssh_key=yes'
[WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly.
192.168.92.20 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 0,
"groups": "yun2",
"home": "/home/yun",
"name": "yun",
"password": "NOT_LOGGING_PASSWORD",
"shell": "/bin/bash",
"ssh_fingerprint": "3072 SHA256:58nnLq7Ayei+ENPof8bGe5jynGmSWyCmXpSVbidfry4 ansible-generated on web20h (RSA)",
"ssh_key_file": "/home/yun/.ssh/id_rsa",
"ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCuT/Nl0BprWkgnXQ7xipGZEG4ap/x+ClUfmGkcY+YwpxF6gZRVhrvIlWtZzJGRfTrhSbvGyJ6m/4zX6AOTdzcV86XAjPc1EcBn3Vjfdor/g4VoZxphM81jV6O9J95RcW21Q3YlvL1+24o81dLjK078i5Vhxpun3wDVAxq5i/HCfB4KH602YgGhECAJe1y77IdZZaR5tiblcYAgBqX+f63HbEKzUx3gMtXW4MxUOS8xNtY302Zmsyn43WqkckmMGJ9b18p36+C1NjGYKV4mnHj56RjwbkajuRH9SH4/9eEGXs20Lcde/PvwBC3OBvDnvkOkxjFP7r/MCzt89UD7bo0DCbSLp0fnIx1PcSphAOL29poFJ1nHEt2LYwQYxGl8ug2ULdy92x0YdHPDSXYbk+z+cSniqAVqwuu9TLfZW/Cm8hqraSl4lh+hEOfoxRiu+J1nSce8QN/MjxeJsIRW1/OgN1xE53OXK63TGOZKZfcUd8biFSjW1ECdVQni9DXooQk= ansible-generated on web20h",
"state": "present",
"system": false,
"uid": 1200
}
[root@ansible ~]#