- 여러대의 서버를 효율적으로 관리하기 위해 고안된 환경 구성 자동화 도구 중 하나로 다음과 같은 특징을 가진다
- Agentless, SSH 사용으로 Push 방식, Python 으로 구현. 오픈소스 자동화 도구, 멱등성 보장
- Ubuntu 20.04 LTS
- 하드웨어 기본 사양
- 4 GB of RAM
- 3.4 GHz CPU with 2 Cores
- Hard disk space 20 GB
- Internet Connection
- 필요한 컴포넌트들
* Ansible
- docker compose
- python
$ sudo apt update
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt update
$ sudo apt install -y docker-ce docker-ce-cli containerd.io
$ sudo usermod -aG docker $USER
$ sudo systemctl restart docker
$ docker version
$ curl -s https://api.github.com/repos/docker/compose/releases/latest \
| grep browser_download_url | grep docker-compose-Linux-x86_64 \
| cut -d '"' -f 4 | wget -qi -
$ sudo chmod +x docker-compose-Linux-x86_64
$ sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
$ docker-compose version
docker-compose version 1.29.2, build unknown
$ sudo apt install -y ansible
$ ansible --version
ansible 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/suji.lee14/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.10 (default, Jun 2 2021, 10:49:15) [GCC 9.4.0]
$ sudo apt install -y nodejs npm
$ sudo apt install -y python3-pip git pwgen
$ sudo pip3 install docker-compose==1.29.2
$ wget https://github.com/ansible/awx/archive/17.1.0.zip
$ unzip 17.1.0.zip
$ cd awx-17.1.0/installer
$ pwgen -N 1 -s 30
BNDLg3WndlIZSvRTjz7JwkyBcEXe4u
$ vi inventory
$ ansible-playbook -i inventory install.yml
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
22b646599acd ansible/awx:17.1.0 "/usr/bin/tini -- /u…" 6 minutes ago Up 6 minutes 8052/tcp awx_task
3e74d23ce81e ansible/awx:17.1.0 "/usr/bin/tini -- /b…" 11 minutes ago Up 6 minutes 0.0.0.0:80->8052/tcp, :::80->8052/tcp awx_web
6a2513cafda2 redis "docker-entrypoint.s…" 12 minutes ago Up 6 minutes 6379/tcp awx_redis
3850007e5f87 postgres:12 "docker-entrypoint.s…" 12 minutes ago Up 6 minutes 5432/tcp awx_postgres
ansible 서버의 IP(80port) 로 접속
# docker-compose up -d
아래 파일에 등록 할 호스트와 그룹을 설정
$ sudo vi /etc/ansible/hosts
[gcpservers]
10.2.1.3
$ ansible gcpservers -m ping
The authenticity of host '10.2.1.3 (10.2.1.3)' can't be established.
ECDSA key fingerprint is SHA256:KFj6rtme8qw9rwfSdQ9mN3RRu8H4ydlv3CFjr+FDBSU.
Are you sure you want to continue connecting (yes/no/[fingerprint])? Y
처음 진행하는 경우 아래와 같이 권한 없음 메시지 노출
10.2.1.3 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Warning: Permanently added '10.2.1.3' (ECDSA) to the list of known hosts.\r\nsuji.lee14@10.2.1.3: Permission denied (publickey).",
"unreachable": true
}
$ ssh-keygen # ansible 서버에서 실행
The key's randomart image is:
+---[RSA 3072]----+
| ooo+.o. oo+.|
| ...=.. .o.* o|
| + . . . = |
| o . . .|
| . S .. .|
| . * . .+ .. |
| = + .+.*. |
| o . oB+=. |
| .=*+ .E|
+----[SHA256]----
$ ls -al ~/.ssh/
authorized_keys id_rsa id_rsa.pub
$ ssh-copy-id sysadm@192.168.1.9
$ ansible gcpservers -m ping
10.2.1.3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
awx 의 경우, awx 내에서 한 작업들은 대부분 postgresql 에 저장이 되므로, 이것만 백업해두면 됩니다.
(playbook 등의 소스는 github 으로 관리)
backup
docker exec -t awx_postgres pg_dump -c -d awx -U awx > awx_backup_db.dmp
restore
cat awx_backup_db.dmp | docker exec -i awx_postgres psql -U awx
https://github.com/ansible/awx/blob/devel/INSTALL.md#upgrading-from-previous-versions
참고자료