ansible achieve mass build trust

Ansible : Automated operation and maintenance tool

Why build mutual trust: ansible batch configuration management is the premise of managed machines and machine ssh trust that the public key management by the host ( id_rsa.pubadd) to the target host, manage machine without going through the interactive input password to log target host.

Build mutual trust :

1, for generating a secret key

$ ssh-keygen -t rsa

Enter all the way to

2, the establishment of mutual trust:

format: ssh-copy-id -i ~/.ssh/id_rsa.pub username@[ip,hostname]  //[]内为目标主机的信息

$ ssh-copy-id -i ~/.ssh/id_rsa.pub username@192.168.1.2

Follow the prompts to complete the operation is complete mutual trust.

Batch build mutual trust :

The establishment of a small amount of trust by the above method of operation is also OK, but if the target host under case number manually executed too slow, so here ansible using the authoried_keys module for batch build trust

Reference: http://docs.ansible.com/authorized_key_module.html

1, configure the hosts file (ansible target host definition file)

$ cat /etc/ansible/hosts

[test]
192.168.12.5[1:4]       #表示192.168.12.51-192.168.12.54
192.168.12.5[6:9]
192.168.13.101
192.168.13.103

2, the establishment playbook (called a script, ansible according to its configuration batch execution command)

CAT pushssh.yaml $ 
--- - hosts: the Test #test Yeah host group name in the hosts file # users trust the User: abm Tasks: - name: SSH - Copy authorized_key: the User = hoxis Key = " {{the Lookup ( ' File ',' /home/abm/.ssh/id_rsa.pub ')}} "

3, execution

$ ansible-playbook pushssh.yaml

 

4, the test

Command: ansible test -m ping

 

Green returns SUCCESS, on behalf of mutual trust can successfully execute ansible batch commands.

 

Guess you like

Origin www.cnblogs.com/-abm/p/11224902.html