Print
카테고리: [ Amazon Web Services ]
조회수: 869

1. 개요

아마존의 Amazon Linux 서버에 ansible을 설치하는 방법이다.


2. 설치

2.1. 인스톨

# amazon-linux-extras install ansible2
Installing ansible
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-ansible2 amzn2extra-docker amzn2extra-kernel-5.10 epel-apache-maven whatap
23 metadata files removed
9 sqlite files removed
0 metadata files removed
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                       | 3.7 kB  00:00:00
amzn2extra-ansible2                                                                              | 3.0 kB  00:00:00
amzn2extra-docker                                                                                | 3.0 kB  00:00:00
amzn2extra-kernel-5.10                                                                           | 3.0 kB  00:00:00
epel-apache-maven                                                                                | 3.3 kB  00:00:00
whatap                                                                                           |  951 B  00:00:00
(1/10): amzn2-core/2/x86_64/group_gz                                                             | 2.5 kB  00:00:00
(2/10): amzn2-core/2/x86_64/updateinfo                                                           | 539 kB  00:00:00
(3/10): amzn2extra-docker/2/x86_64/primary_db                                                    |  99 kB  00:00:00
(4/10): amzn2extra-kernel-5.10/2/x86_64/updateinfo                                               |  22 kB  00:00:00
(5/10): amzn2extra-ansible2/2/x86_64/updateinfo                                                  |   76 B  00:00:00
(6/10): amzn2extra-ansible2/2/x86_64/primary_db                                                  |  39 kB  00:00:00
(7/10): amzn2extra-docker/2/x86_64/updateinfo                                                    | 8.0 kB  00:00:00
(8/10): amzn2extra-kernel-5.10/2/x86_64/primary_db                                               |  14 MB  00:00:00
(9/10): amzn2-core/2/x86_64/primary_db                                                           |  68 MB  00:00:00
(10/10): epel-apache-maven/x86_64/primary_db                                                     | 5.0 kB  00:00:01
whatap/x86_64/primary                                                                            |  16 kB  00:00:00
whatap                                                                                                          180/180
Resolving Dependencies
--> Running transaction check
---> Package ansible.noarch 0:2.9.23-1.amzn2 will be installed
--> Processing Dependency: sshpass for package: ansible-2.9.23-1.amzn2.noarch
--> Processing Dependency: python-paramiko for package: ansible-2.9.23-1.amzn2.noarch
--> Processing Dependency: python-keyczar for package: ansible-2.9.23-1.amzn2.noarch
--> Processing Dependency: python-httplib2 for package: ansible-2.9.23-1.amzn2.noarch
--> Processing Dependency: python-crypto for package: ansible-2.9.23-1.amzn2.noarch
--> Running transaction check
---> Package python-keyczar.noarch 0:0.71c-2.amzn2 will be installed
---> Package python2-crypto.x86_64 0:2.6.1-13.amzn2.0.3 will be installed
--> Processing Dependency: libtomcrypt.so.1()(64bit) for package: python2-crypto-2.6.1-13.amzn2.0.3.x86_64
---> Package python2-httplib2.noarch 0:0.18.1-3.amzn2 will be installed
---> Package python2-paramiko.noarch 0:1.16.1-3.amzn2.0.2 will be installed
--> Processing Dependency: python2-ecdsa for package: python2-paramiko-1.16.1-3.amzn2.0.2.noarch
---> Package sshpass.x86_64 0:1.06-1.amzn2.0.1 will be installed
--> Running transaction check
---> Package libtomcrypt.x86_64 0:1.18.2-1.amzn2.0.1 will be installed
--> Processing Dependency: libtommath >= 1.0 for package: libtomcrypt-1.18.2-1.amzn2.0.1.x86_64
--> Processing Dependency: libtommath.so.1()(64bit) for package: libtomcrypt-1.18.2-1.amzn2.0.1.x86_64
---> Package python2-ecdsa.noarch 0:0.13.3-1.amzn2.0.1 will be installed
--> Running transaction check
---> Package libtommath.x86_64 0:1.0.1-4.amzn2.0.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                      Arch               Version                          Repository                       Size
========================================================================================================================
Installing:
 ansible                      noarch             2.9.23-1.amzn2                   amzn2extra-ansible2              17 M
Installing for dependencies:
 libtomcrypt                  x86_64             1.18.2-1.amzn2.0.1               amzn2extra-ansible2             409 k
 libtommath                   x86_64             1.0.1-4.amzn2.0.1                amzn2extra-ansible2              36 k
 python-keyczar               noarch             0.71c-2.amzn2                    amzn2extra-ansible2             218 k
 python2-crypto               x86_64             2.6.1-13.amzn2.0.3               amzn2extra-ansible2             476 k
 python2-ecdsa                noarch             0.13.3-1.amzn2.0.1               amzn2extra-ansible2              94 k
 python2-httplib2             noarch             0.18.1-3.amzn2                   amzn2extra-ansible2             125 k
 python2-paramiko             noarch             1.16.1-3.amzn2.0.2               amzn2extra-ansible2             259 k
 sshpass                      x86_64             1.06-1.amzn2.0.1                 amzn2extra-ansible2              22 k

Transaction Summary
========================================================================================================================
Install  1 Package (+8 Dependent packages)

Total download size: 19 M
Installed size: 110 M
Is this ok [y/d/N]:

2.2. 설치 후 버전 확인

# ansible --version
ansible 2.9.23
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.18 (default, May 25 2022, 14:30:51) [GCC 7.3.1 20180712 (Red Hat 7.3.1-15)]

3. 컨트롤러 서버와 원격 서버 설정

3.1. 컨트롤러 서버에서 ssh 키 생성

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ec2-user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ec2-user/.ssh/id_rsa.
Your public key has been saved in /home/ec2-user/.ssh/id_rsa.pub.
The key fingerprint is:
...

$ ls -al .ssh/
합계 20
drwx------  2 ec2-user ec2-user   80  1월 10 09:55 .
drwx------ 14 ec2-user ec2-user 4096 11월 30 07:22 ..
-rw-------  1 ec2-user ec2-user  401 10월 18 00:31 authorized_keys
-rw-------  1 ec2-user ec2-user 1679  1월 10 09:55 id_rsa
-rw-r--r--  1 ec2-user ec2-user  438  1월 10 09:55 id_rsa.pub

키 내용을 확인한다.

$ cat .ssh/id_rsa.pub

위 내용을 잘 기억한다.

3.2. 원격 서버 작업

위 내용을 아래 파일의 끝에 붙여넣는다.

vi .ssh/authorized_keys

 


4. 원격 서버 등록

컨트롤러 서버 원격 서버 IP 주소를 등록한다.

sudo vi /etc/ansible/hosts

그리고 ansible 명령어를 이용하여 ping을 날려본다.

ansible all -m ping
[WARNING]: Platform linux on host 10.21.110.92 is using the discovered Python interpreter at /usr/bin/python, but
future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
10.21.110.92 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}