반응형
우분투에서 최신 버전의 ansible을 설치하는 방법
테스트 환경
$ lsb_release -d
Description: Ubuntu 22.04.2 LTS
우분투에서 apt를 사용하여 최신 버전의 ansible을 설치하려면 다음과 같은 단계를 따르면 됩니다.
1. 패키지 관리자의 패키지 목록을 업데이트합니다.
sudo apt update
sudo apt install software-properties-common
2. Ansible PPA 저장소를 추가합니다.
sudo add-apt-repository --yes --update ppa:ansible/ansible
$ sudo add-apt-repository --yes --update ppa:ansible/ansible
Repository: 'deb https://ppa.launchpadcontent.net/ansible/ansible/ubuntu/ jammy main'
Description:
Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.
http://ansible.com/
If you face any issues while installing Ansible PPA, file an issue here:
https://github.com/ansible-community/ppa/issues
More info: https://launchpad.net/~ansible/+archive/ubuntu/ansible
Adding repository.
Adding deb entry to /etc/apt/sources.list.d/ansible-ubuntu-ansible-jammy.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/ansible-ubuntu-ansible-jammy.list
Adding key to /etc/apt/trusted.gpg.d/ansible-ubuntu-ansible.gpg with fingerprint 6125E2A8C77F2818FB7BD15B93C4A3FD7BB9C367
...
3. 저장소를 업데이트하고 Ansible을 설치합니다.
sudo apt update
sudo apt install -y ansible
4. 설치를 확인하기 위해 Ansible 버전을 확인합니다.
ansible --version
$ ansible --version
ansible [core 2.14.5]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] (/usr/bin/python3)
jinja version = 3.0.3
libyaml = True
5. ac-hoc 명령어로 ping 테스트하는 방법
ansible -m ping localhost
$ ansible -m ping localhost
localhost | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
728x90
6. ansible-playbook 명령어로 ping 테스트하는 방법
- ansible.cfg 파일 생성
- 모든 기본 설정이 주석 처리된 "disabled" 구성 파일을 생성
ansible-config init --disabled > ansible.cfg
- 기존 플러그인을 포함하여 더욱 완벽한 파일을 생성
ansible-config init --disabled -t all > ansible.cfg
- ansible.cfg 파일 편집
vim ansible.cfg
[defaults]
inventory = ~/git-root/ansible-cli/inventory/hosts.ini
host_key_checking = False
ansible --version
$ ansible --version
ansible [core 2.14.6]
config file = /home/vagrant/git-root/ansible-cli/ansible.cfg
configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0] (/usr/bin/python3)
jinja version = 3.0.3
libyaml = True
- hosts.ini 파일 생성
mkdir inventory
vim inventory/hosts.ini
$ cat inventory/hosts.ini
[all]
[local]
localhost ansible_connection=local
- 인벤토리 목록 확인
ansible-inventory --graph
$ ansible-inventory --graph
@all:
|--@ungrouped:
|--@local:
| |--localhost
$ ansible-inventory -i inventory/hosts.ini --graph
@all:
|--@ungrouped:
|--@local:
| |--localhost
- ping.yml 파일 생성
$ cat ping.yml
---
- name: Ping all hosts
hosts: all
gather_facts: no
vars:
ansible_python_interpreter: /usr/bin/python3
tasks:
- name: Ping test
ping:
- 플레이북 문법 검사
ansible-playbook -i inventory/hosts.ini ping.yml --syntax-check
$ ansible-playbook -i inventory/hosts.ini ping.yml --syntax-check
playbook: ping.yml
- 플레이북 실행
ansible-playbook -i inventory/hosts.ini ping.yml --limit local
$ ansible-playbook -i ../inventory/hosts.ini ping.yml --limit local
PLAY [Ping all hosts] ***********************************************************************************************
TASK [Ping test] ****************************************************************************************************
ok: [localhost]
PLAY RECAP **********************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
참고URL
- Ansible Documentation : Installing Ansible on Ubuntu
728x90
반응형
'리눅스' 카테고리의 다른 글
docker proxy 설정하는 방법(환경 변수 구성) (0) | 2023.05.11 |
---|---|
nginx와 php-fpm을 사용하는 경우 *.html 파일에서도 PHP 코드를 실행하도록 설정하는 방법 (0) | 2023.05.09 |
Packer 명령어의 자동 완성을 활성화하는 방법 (0) | 2023.05.02 |
Nginx 및 Apache 웹 서버에서 HTTP/2를 적용하는 방법 (0) | 2023.04.28 |
웹 서버가 HTTP/2 프로토콜을 지원하는지 확인하는 방법 (0) | 2023.04.28 |