본문 바로가기

퍼블릭 클라우드

[Ansible] Amazon Linux에 Ansible 설치하기

반응형

Amazon Linux에 Ansible 설치하기

설치 환경

$ cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"

Ansible 설치하기

$ amazon-linux-extras install ansible2
Installing:
 ansible
Installing for dependencies:
 libtomcrypt
 libtommath
 python-keyczar
 python-paramiko
 python2-crypto
 python2-httplib2
 sshpass

Ansible 버전

$ ansible --version
ansible 2.9.20
  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, Feb 18 2021, 06:07:59) [GCC 7.3.1 20180712 (Red Hat 7.3.1-12)]

Ansible inventory(hosts) 설정

$ vim /etc/ansible/hosts
[dbs]
db1 ansible_host=10.31.3.72 ansible_connection=ssh ansible_por=22 ansible_user=ec2-user ansible_ssh_private_key_file=~/aws-key/keyfile.pem
db2 ansible_host=10.31.4.78 ansible_connection=ssh ansible_por=22 ansible_user=ec2-user ansible_ssh_private_key_file=~/aws-key/keyfile.pem
db3 ansible_host=10.31.3.63 ansible_connection=ssh ansible_por=22 ansible_user=ec2-user ansible_ssh_private_key_file=~/aws-key/keyfile.pem

Ansible 호스트 키(Host Key) 검사 비활성화

- default : 호스트 키(Host Key) 검사 활성화

$ ansible dbs -m ping
The authenticity of host '10.31.3.63 (10.31.3.63)' can't be established.
ECDSA key fingerprint is SHA256:PIhyKHI8ITVqf1SAeWB4k7ialx2SNqvJ6.
ECDSA key fingerprint is MD5:b4:de:cb:e9:8f:35:8a:a4:7d:12:01:ba:.
Are you sure you want to continue connecting (yes/no)? yes

호스트 키(Host Key) 검사 비활성화 설정

$ vim /etc/ansible/ansible.cfg
...

# uncomment this to disable SSH key host checking
host_key_checking = False
...

Python Path WARNING

- 클라이언트 python 경로 확인

[root@ip-10-31-3-72 ~]$ which python
/usr/bin/python
$ ansible dbs -m ping
[WARNING]: Platform linux on host db3 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.

inventory(hosts) 설정 변경

- ansible_python_interpreter=/usr/bin/python 설정

$ vim /etc/ansible/hosts
[dbs:vars]
ansible_connection=ssh
ansible_port=22
ansible_ssh_user=ec2-user
ansible_ssh_private_key_file=~/aws-key/keyfile.pem
ansible_python_interpreter=/usr/bin/python

[dbs]
db1 ansible_host=10.31.3.72
db2 ansible_host=10.31.4.78
db3 ansible_host=10.31.3.63

ping 테스트

$ ansible dbs -m ping
db3 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
db2 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
db1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

 

https://runebook.dev/ko/docs/ansible/user_guide/intro_inventory#splitting-out-vars

 

Ansible - 인벤토리를 구축하는 방법 - Ansible works against multiple managed nodes or “hosts” in your infrastructu

인벤토리를 구축하는 방법 Ansible works against multiple managed nodes or “hosts” in your infrastructure at the same time, using a list or group of lists known as inventory. Once your inventory is defined, you use patterns to select the hosts

runebook.dev

 

 

728x90
반응형