代码
y97?L^XnVJP@rpv*u@eW
$6$rounds=656000$nMclP3FUj.DCePbE$FV/tOLx8Mkb8eV6K0I7upRlc4Kpv...t0xIIolLXnk8NapyO5vf5QPihzJ9VGTfNqq6yulsREtQ/19QODeACt/
- hosts: all
vars:
user: wangguan
password: "$6$rounds=656000$w.sF/w4vQWOOn4Xx$q0MHTEsT4jDvmEWiZ7jcK4l/7iqSxSrnDFxY9H5wmfMpkJcXk41tgTc5Jt8S8YJyla7iKaZL4NYHI2p4mJ9NW."
remote_user: root
tasks:
- name: Add user {{ user }}
user: name={{user}} comment="wangguan user" password={{ password }}
- name: Config /etc/sudoers
lineinfile: dest=/etc/sudoers state=present line='{{item}}' validate='visudo -cf %s'
with_items:
- "{{ user}} ALL=(ALL) NOPASSWD: ALL"
- "Defaults: {{user}} !requiretty"
register: result
- name: Show info
debug: var=result.stdout verbosity=0


执行结果
[root@ansible ansible]# ansible-playbook adduser.yml -k
SSH password:

PLAY [all] *******************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************************************************************************************************************************
ok: [192.168.61.30]

TASK [Add user wangguan] *********************************************************************************************************************************************************************************************************************************************************
changed: [192.168.61.30]

TASK [Config /etc/sudoers] ***************************************************************************************************************************************************************************************************************************************************
changed: [192.168.61.30] => (item=wangguan ALL=(ALL) NOPASSWD: ALL)
changed: [192.168.61.30] => (item=Defaults: wangguan !requiretty)

TASK [Show create user info] *******************************************************************************************************************************************************************************************************************************************************
ok: [192.168.61.30] => {
"result.stdout": "VARIABLE IS NOT DEFINED!"
}

PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************
192.168.61.30 : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0


$6$rounds=656000$I25/pgd1YeMpYG6G$7.hKPDuFZUfWf86gdggTGY9ezH.84kWnv8OqR6/0suAsT/IdmbQ3o07igu3ydsJLLos8E4O7u1Qs7UlKYxNYC/