ansible execute playbook
ansible을 이용한 playbook 실행
[root@localhost ~]# vi /etc/ansible/hosts
192.168.0.116 ansible_connection=ssh ansible_ssh_user=min ansible_ssh_pass=xxxxxx ansible_ssh_common_args='-o StrictHostKeyChecking=no'
192.168.0.177 ansible_connection=ssh ansible_ssh_user=min ansible_ssh_pass=xxxxxx ansible_ssh_common_args='-o StrictHostKeyChecking=no'
[root@localhost ~]# vi test.yml
- hosts: testgroup
tasks:
- script: /usr/bin/date >> /tmp/date.log
[root@localhost ~]# ansible-playbook test.yml
PLAY [testgroup] ******************************************************************************************************************************
TASK [Gathering Facts] ************************************************************************************************************************
ok: [192.168.0.116]
ok: [192.168.0.156]
ok: [192.168.0.177]
TASK [script] *********************************************************************************************************************************
changed: [192.168.0.116]
changed: [192.168.0.156]
changed: [192.168.0.177]
PLAY RECAP ************************************************************************************************************************************
192.168.0.116 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.0.156 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.0.177 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[root@localhost ~]#
1. 환경준비
Centos 7.x
2. edit playbook
[root@localhost ~]# vi /etc/ansible/hosts
[testgroup]
192.168.0.156 ansible_connection=ssh ansible_ssh_user=min ansible_ssh_pass=xxxxxx ansible_ssh_common_args='-o StrictHostKeyChecking=no'192.168.0.116 ansible_connection=ssh ansible_ssh_user=min ansible_ssh_pass=xxxxxx ansible_ssh_common_args='-o StrictHostKeyChecking=no'
192.168.0.177 ansible_connection=ssh ansible_ssh_user=min ansible_ssh_pass=xxxxxx ansible_ssh_common_args='-o StrictHostKeyChecking=no'
- hosts: testgroup
tasks:
- script: /usr/bin/date >> /tmp/date.log
~
~[root@localhost ~]# ansible-playbook test.yml
PLAY [testgroup] ******************************************************************************************************************************
TASK [Gathering Facts] ************************************************************************************************************************
ok: [192.168.0.116]
ok: [192.168.0.156]
ok: [192.168.0.177]
TASK [script] *********************************************************************************************************************************
changed: [192.168.0.116]
changed: [192.168.0.156]
changed: [192.168.0.177]
PLAY RECAP ************************************************************************************************************************************
192.168.0.116 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.0.156 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.0.177 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
댓글
댓글 쓰기