Install Ansible on CentOS 7

1.Ansible 설치

- control node 에 ssh-keygen 생성하기

[root@ansible-control ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
...

- 생성된 key 를 host 서버에 전송하기

#### ssh-key 전송하기
[root@ansible-control ~]# ssh-copy-id hosta
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@hosta's password:
 
Number of key(s) added: 1
 
Now try logging into the machine, with:   "ssh 'hosta'"
and check to make sure that only the key(s) you wanted were added.
 
[root@ansible-control ~]# ssh-copy-id hostb
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@hostb's password:
 
Number of key(s) added: 1
 
Now try logging into the machine, with:   "ssh 'hostb'"
and check to make sure that only the key(s) you wanted were added.
 
### 접속 확인
[root@ansible-control ~]# ssh hosta
Last login: Wed Jan 27 14:42:56 2021 from ansible-hostb.test.com
[root@ansible-hosta ~]# exit
logout
Connection to hosta closed.
[root@ansible-control ~]# ssh hostb
Last login: Wed Jan 27 14:42:07 2021 from ansible-control.test.com
[root@ansible-hostb ~]# exit
logout
Connection to hostb closed.

- Ansible 설치를 위해 EPEL Repository 추가 하기

[root@ansible-control ~]# yum install epel-release
[root@ansible-control ~]# yum search ansible

- Control 서버에 Ansible 설치하기

[root@ansible-control ~]# yum install epel-release
[root@ansible-control ~]# yum search ansible
[root@ansible-control ~]# yum install epel-release
[root@ansible-control ~]# yum search ansible