Used to play ansible, the root account is used to manage. Now to the production environment, can not be so casual, I believe that many other companies are also banned from the root SSH connection.
Therefore, I have a problem with this deployment, many articles on the internet, are not elaborate on this piece. I also groping to do out, through this practice, but also further deepened the understanding of ansible. Hope can help the vast number of friends.
The deployment steps are as follows
1.1 Checking the Ansible.cfg configuration file on the management machine
# vi/etc/ansible/ansible.cfg
Sudo_user = root/* Make sure the configuration is like this */
1.2 The default ansible is verified with key
If you use a password to log on to the server, use Ansible,
Do not modify the Ansible.cfg configuration file to ask_pass= true to uncomment,
Or just add-K when you run the command, which means-K,--ask-pass ask for SSH password
1.3 If the client is not in the know_hosts will be an error
If you want to resolve this issue, you need to modify Ansible.cfg's #host_key_checking = False Uncomment
1.4 Create a regular account on the management machine and add sudo
# Useradd CPIs
# passwd CPIs
# vi/etc/sudoers
CPIs all= (All) Nopasswd:all
1.5 Create a regular account on the managed machine and add sudo
# Useradd CPIs
# passwd CPIs
# vi/etc/sudoers
CPIs all= (All) Nopasswd:all
1.6 The key is generated on the management machine and copied to the managed machine
# Su-cpis
[[email protected] ~]$ ssh-keygen-t RSA
[Email protected] ~]$ ssh-copyid-i 172.31.28.61
1.7 Management machine to do the test
# ansible 172.31.28.61-u CPIs--sudo-a ' Ls/root '
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/D5/wKioL1S-FA6S2OWtAAEYQD2IEuI685.jpg "title=" 3.png " alt= "Wkiol1s-fa6s2owtaaeyqd2ieui685.jpg"/>
This means that the test passes, and it achieves our original purpose.
This article from "Hanyun.fang" blog, reproduced please contact the author!
Ansible--General account to do batch deployment