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

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

  - 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: []

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

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

Be the first to comment

Leave a Reply