Ansible basis Centos 7.4

Host environment for the Centos 7.4

192.168.241.100 management node 

192.168.241.101 host

192.168.241.102 host

Installation Ansible (to ensure their own virtual machine can access the Internet)

[root@liudongyi ~]# yum install ansible -y

A connection to the remote host authentication: configure the host name of the file Ansible (add two host nodes use ssh password for authentication)

[root@liudongyi ~]# vim /etc/ansible/hosts 

[webservers]
192.168.241.101 ansible_ssh_user=root ansible_ssh_pass='centos'
192.168.241.102 ansible_ssh_user=root ansible_ssh_pass='centos'

After the save. We test the green ping successfully conducted on our behalf

[root@liudongyi ~]# ansible webservers -m ping

Option 2: ssh key authentication

[root@liudongyi ~]# vim /etc/ansible/hosts 

[webservers]
192.168.241.101 
192.168.241.102 

Generate the key:

[root@liudongyi ~]# ssh-keygen      一路回车

We copy the generated public key to another host

[root@liudongyi ~]# ssh-copy-id [email protected]

Then we do not need to ssh to 192.168.241.101 enter the password

The same way we copy the public key to the host computer 102, and then we modify the host configuration file:

[root@liudongyi ~]# vim /etc/ansible/hosts 
[webservers]
192.168.241.101 ansible_ssh_user=root ansible_ssh_key=/root/.ssh/id_rsa
192.168.241.102 ansible_ssh_user=root ansible_ssh_key=/root/.ssh/id_rsa

We then tested the ping:

Simple command to test:

ansible all -m ping
ansible all -m shell -a "ls /root" -u root -k 
ansible webservers -m copy –a "src=/etc/hosts dest=/tmp/hosts"

 

 

 

 

Published 48 original articles · won praise 3 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_40210617/article/details/104221701