exam 3

We have phpnginx and mariadb installed on node02 and have a DB mydb created there. The user to connect to DB is myuser and password is mypassword. Create a playbook ~/playbooks/database.yml to perform below given tasks:


a. Start nginx and mariadb services.

b. Delete all default files/directories from nginx document root /usr/share/nginx/html/

c. Download a zip archive from https://github.com/indercodes/ansible-1100-mock-nginx/raw/master/index.php.zip and extract it in /usr/share/nginx/html/

d. The archive have an index.php file to check DB connectivity. Replace some required DB details in the file using replace or lineinfile module:

$database = "database"; to $database = "mydb";

$username = "user"; to $username = "myuser";

$password = "password"; to $password = "mypassword";

e. Restart nginx after making required changes.







Create database.yml playbook and add below given code
---
- hosts: node02
  tasks:
    - name: Start service nginx
      service:
        name: "{{ item }}"
        state: started
      with_items:
        - nginx
        - mariadb

    - name: clean nginx document root
      shell: rm -rf /usr/share/nginx/html/*

    - name: download zip
      unarchive: 
        src: https://github.com/indercodes/ansible-1100-mock-nginx/raw/master/index.php.zip
        dest: /usr/share/nginx/html/
        remote_src: yes

    - name: Update DB details
      replace:
        path: /usr/share/nginx/html/index.php
        regexp: '{{ item.1 }}'
        replace: '{{ item.2 }}'
      with_items:
        - { 1: '\$database.*', 2: '$database = "mydb";' }
        - { 1: '\$username.*', 2: '$username = "myuser";' }
        - { 1: '\$password.*', 2: '$password = "mypassword";' }

    - name: restart Nginx
      service:
        name: nginx
        state: restarted


Comments

Popular posts from this blog

exam 16

ansible 5

practical 3