centos7 에서 테스트 하였습니다.
ansible 서버에서 ..
[root@template-cent7 /tmp]# yum install ansible
[root@template-cent7 /tmp]# ssh-keygen -t rsa
그냥 계속 < enter >
ansible 클라이언트에서 ..
[root@template-cent7 /tmp]# useradd ansible
[root@template-cent7 /tmp]# echo "password" | passwd --stdin ansible
다시 ansible 서버에서 ..
[root@template-cent7 /tmp]# cd /root/.ssh
[root@template-cent7 /root/.ssh]# ssh-copy-id -i id_rsa.pub ansible@192.168.231.64
[root@template-cent7 /tmp]# vi test.ini
test ansible_host=192.168.231.64 ansible_user=ansible
[root@template-cent7 /tmp]# ansible -m ping -i test.ini all
test1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
# playbook 예제
[root@template-cent7 /tmp]# cat mcelog.yaml
---
- name: test
hosts: all
become: true
tasks:
- name: mcelog package install
yum:
name: mcelog
state: installed
[root@template-cent7 /tmp]# cat test.ini
test1 ansible_host=192.168.231.64 ansible_user=1-ansible
test2 ansible_host=192.168.231.65 ansible_user=1-ansible
test3 ansible_host=192.168.231.66 ansible_user=1-ansible
[test-group]
test1
test2
[root@template-cent7 /tmp]# ansible-playbook -i test.ini mcelog.yaml
인벤토리는 위와 같이 파일을 직접 지정하거나, 해당 경로에 등록하여 사용할 수 있음
/etc/ansible/hosts
# shell 모듈 사용
[root@template-cent7 /tmp]# ansible test1 -m shell -a "cat /etc/hosts"
# 모듈 리스트
https://docs.ansible.com/ansible/latest/modules/list_of_all_modules.html
# 모듈 설명보기
[root@template-cent7 /tmp]# ansible-doc <module_name>