Ansible script to install httpd package and enable httpd during boot.
Step 1.
[root@cluster playbooks]# pwd
/root/playbooks
[root@cluster playbooks]# cat hosts
[webservers]
169.254.41.221
169.254.41.222
Step2.
[root@cluster playbooks]# cat httpd.yml
---
- name: Install httpd package and start the service
hosts: webservers
tasks:
- name: install httpd
yum: name=httpd update_cache=yes
- name: enable httpd on boot
service: name=httpd enabled=yes
- name: start the service
service: name=httpd state=started
Step3.
Run
[root@cluster playbooks]# ansible-playbook httpd.yml
Output:
PLAY [Install httpd package and start the service] *****************************
TASK [setup] *******************************************************************
ok: [169.254.41.221]
ok: [169.254.41.222]
TASK [install httpd] ***********************************************************
changed: [169.254.41.221]
changed: [169.254.41.222]
TASK [enable httpd on boot] ****************************************************
changed: [169.254.41.222]
changed: [169.254.41.221]
TASK [start the service] *******************************************************
changed: [169.254.41.222]
changed: [169.254.41.221]
PLAY RECAP *********************************************************************
169.254.41.221 : ok=4 changed=3 unreachable=0 failed=0
169.254.41.222 : ok=4 changed=3 unreachable=0 failed=0
Step 1.
[root@cluster playbooks]# pwd
/root/playbooks
[root@cluster playbooks]# cat hosts
[webservers]
169.254.41.221
169.254.41.222
Step2.
[root@cluster playbooks]# cat httpd.yml
---
- name: Install httpd package and start the service
hosts: webservers
tasks:
- name: install httpd
yum: name=httpd update_cache=yes
- name: enable httpd on boot
service: name=httpd enabled=yes
- name: start the service
service: name=httpd state=started
Step3.
Run
[root@cluster playbooks]# ansible-playbook httpd.yml
Output:
PLAY [Install httpd package and start the service] *****************************
TASK [setup] *******************************************************************
ok: [169.254.41.221]
ok: [169.254.41.222]
TASK [install httpd] ***********************************************************
changed: [169.254.41.221]
changed: [169.254.41.222]
TASK [enable httpd on boot] ****************************************************
changed: [169.254.41.222]
changed: [169.254.41.221]
TASK [start the service] *******************************************************
changed: [169.254.41.222]
changed: [169.254.41.221]
PLAY RECAP *********************************************************************
169.254.41.221 : ok=4 changed=3 unreachable=0 failed=0
169.254.41.222 : ok=4 changed=3 unreachable=0 failed=0
Comments
Post a Comment