Ansible Demo
Installing Ansible on CentOS 7 Machine 1 (Eg IP: 192.168.56.101)
yum install -y ansible
Creating inventory file
$ mv /etc/ansible/hosts /etc/ansible/hosts.orig
$ vi /etc/ansible/hosts
[web]
192.168.56.102 ansible_ssh_pass=<Password> ansible_ssh_user=<UserName>
Save this file with "!wq" command.
Creating Playbook file
$vi SamplePlaybook.yml
---
- hosts: web
tasks:
- name: install apache
yum: name=httpd state=latest
- name: copy my indexfile
template: src=/root/index.html dest=/var/www/index.html
notify:
- restart apache
- name: ensure apache is running
service: name=httpd state=started enabled=yes
handlers:
- name: restart apache
service: name=httpd state=restarted
Save this file with "!wq" command.
Now execute this file using ansible playbook command:
$ ansible-playbook SamplePlaybook.yml
Output
----------------------------------------------------------------------------------
PLAY [web] *********************************************************************
TASK [setup] *******************************************************************
ok: [192.168.56.102]
TASK [install apache] **********************************************************
ok: [192.168.56.102]
TASK [copy my indexfile] *******************************************************
changed: [192.168.56.102]
TASK [ensure apache is running] ************************************************
changed: [192.168.56.102]
RUNNING HANDLER [restart apache] ***********************************************
changed: [192.168.56.102]
PLAY RECAP *********************************************************************
192.168.56.102 : ok=5 changed=3 unreachable=0 failed=0
No comments:
Post a Comment