# host file under /etc/ansible/hosts
# [root@Ansible-S1 ~]# cat /etc/ansible/hosts
[web]
192.168.184.130
192.168.184.131
#installhttp.yml file
—
– name: install and start apache
hosts: web
remote_user: root
become_method: sudo
become_user: root
vars:
http_port: 80
max_clients: 200
tasks:
– name: install httpd
yum: name=httpd state=present
– name: start httpd
service: name=httpd state=restarted
handlers:
– name: restart apache
# Now run the play-book:
[root@Ansible-S1 ~]# ansible-playbook installhttp.yml
PLAY [install and start apache] **************************************************************************
TASK [Gathering Facts] ***********************************************************************************
ok: [192.168.184.130]
ok: [192.168.184.131]
TASK [install httpd] *************************************************************************************
ok: [192.168.184.130]
ok: [192.168.184.131]
TASK [start httpd] ***************************************************************************************
changed: [192.168.184.130]
changed: [192.168.184.131]
PLAY RECAP ***********************************************************************************************
192.168.184.130 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.184.131 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Leave a comment