Today a requirement, want ansible the command sudo by ordinary users, rather than to perform system administration commands as root user. Proceed as follows
First, the first modification ansible.cfg files, enable sudo, sudo user to specify lisi
forks = 5
#poll_interval = 15
sudo_user = lisi
#ask_sudo_pass = True
#ask_pass = True
Second, sudo is enabled on the managed host, add the user's sudo
visudo
Third, the modified ansible ends hosts file, as follows
[test]
192.168.52.134 ansible_ssh_user=lisi ansible_ssh_pass='123' ansible_sudo_pass='123'
You can specify ssh remote connection password, and the password for end customers when sudo
Fourth, and finally execute commands remotely
ansible test -m command -a "df -hT" -u lisi --sudo -k
-U when performing remote users, and enable sudo user agreement --sudo represent sudo -k represents ssh connection password
192.168.52.134 | SUCCESS | rc=0 >>
File system type available capacity has been used with a mount point%
/dev/mapper/centos-root xfs 17G 4.1G 13G 25% /
devtmpfs devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 492M 0 492M 0% /dev/shm
tmpfs tmpfs 492M 8.1M 483M 2% /run