Install httpd using Ansible


This is an exmaple of how to install httpd apache using ansible. In this example we created a host group called webservers and placed a host in it

[root@centos02 ~]# cat /etc/ansible/hosts
127.0.0.1
[webservers]
192.168.1.13

Next I created a playbook with yaml which instructs ansible to install httpd with the latest version to all hosts in the webservers group. This will run as root.

[root@centos02 ~]# cat playbook2.yaml
---
- hosts: webservers
  remote_user: root

  tasks:
  - name: ensure apache is at the latest version
    yum: name=httpd state=latest

Now you can run the playbook and notice the results. It noticed that httpd was not installed so it installed it and we got an OK response code

[root@centos02 ~]# ansible-playbook playbook2.yaml

PLAY [webservers] **************************************************************

TASK [Gathering Facts] *********************************************************
ok: [192.168.1.13]

TASK [ensure apache is at the latest version] **********************************
changed: [192.168.1.13]

PLAY RECAP *********************************************************************
192.168.1.13               : ok=2    changed=1    unreachable=0    failed=0