Open Source For You — December 2017

(Steven Felgate) #1
How To Admin

http://www.OpenSourceForU.com | OPEN SOURCE FOR YOU | DECEMBER 2017 | 39

The Ansible playbook updates the software package
repository by running apt-get update and then proceeds to
install the Apache2 package. The playbook waits for the server
to start and listen on port 80. An execution of the playbook is
shown below:

$ ansible-playbook -i inventory/kvm/inventory playbooks/
configuration/piwigo.yml --tags web -K
SUDO password:

PLAY [Install Apache web server] ******************
TASK [setup] ***********************************
ok: [ubuntu]

TASK [Update the software package repository] *************
changed: [ubuntu]

TASK [Install Apache] ***************************************
changed: [ubuntu] => (item=[u’apache2’])

TASK [wait_for] *********************************************
ok: [ubuntu]

PLAY RECAP **************************************************
ubuntu : ok=4 changed=2
unreachable=0 failed=0

The verbosity in the Ansible output can be achieved by
passing ‘v’ multiple times in the invocation. The more number
of times that ‘v’ is present, the greater is the verbosity level. The
-K option will prompt for the sudo password for the xetex user.
If you now open http://192.168.122.4, you should be able to see
the default Apache2 index.html page as shown in Figure 1.

MySQL
Piwigo requires a MySQL database server for its back-end,

“ubuntu” VM as indicated below:


192.168.122.4 ubuntu


You should be able to issue commands from Ansible to
the guest OS. For example:


$ ansible ubuntu -m ping


ubuntu | SUCCESS => {
“changed”: false,
“ping”: “pong”
}


On the host system, we will create a project directory
structure to store the Ansible playbooks:


ansible/inventory/kvm/
/playbooks/configuration/
/playbooks/admin/


An ‘inventory’ file is created inside the inventory/kvm
folder that contains the following:


ubuntu ansible_host=192.168.122.4 ansible_connection=ssh
ansible_user=xetex ansible_password=pass


Apache
The Apache Web server needs to be installed first on the
Ubuntu guest VM. The Ansible playbook for the same
is as follows:



  • name: Install Apache web server
    hosts: ubuntu
    become: yes
    become_method: sudo
    gather_facts: true
    tags: [web]


tasks:



  • name: Update the software package repository
    apt:
    update_cache: yes

  • name: Install Apache
    package:
    name: “{{ item }}”
    state: latest
    with_items:

  • apache2

  • wait_for:
    port: 80


Figure 1: Apache2 default index page
Free download pdf