Sunday, July 14, 2019

using blocks in ansjble

#Using blocks in ansible, Playbook to install configure apache.
================================================


[root@ansimaster:~/ansiroot/playbook]# vi mange_web_intranet_2.yml
---
 - name: Playbook to install configure and verify web and database status.
   hosts: webservers
   tasks:
   - block:
     - name: installing httpd package.
       yum:
         name: httpd
         state: present
     - name: installtaling firewalld
       yum:
         name: firewalld
         state: present
     - name: installtaling mariadb-server
       yum:
        name: mariadb-server
        state: present

     - name:
       yum:
        name: php
        state: present
     - name:
       yum:
        name: php-mysql
        state: present

   - block:
     - name: Friewalld permits http service.
       firewalld:
        service: http
        permanent: true
        state: enabled
        immediate: yes

     - name: Starting web service.
       service:
        name: httpd
        enabled: true
       state: started

   - block:
     - name: Deploying http config.
       copy: src=/root/ansiroot/config/httpd/ dest=/usr/share/httpd/noindex/

       notify:
        - restart httpd
     - name: ensure httpd is running
       service:
         name: httpd
         state: started
   handlers:
      - name: restart httpd
        service:
         name: httpd
         state: restarted

 - name: Playbook to test Mylinuxfriend blog working in intranet.
   hosts: webservers
   tasks:
    - name: connected to intranet...!
      uri:
        url: http://192.168.122.50
        status_code: 200

## END of playbook mange_web_intranet_2.yml ######
wq!

[root@ansimaster:~/ansiroot/playbook]#

============================
  Now lets check your playbook syntex
============================

[root@ansimaster:~/ansiroot/playbook]# ansible-playbook mange_web_intranet_2.yml -C
 [WARNING]: Ignoring invalid attribute: state


PLAY [Playbook to install configure and verify web and database status.] ************************************************************************************************

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

TASK [installing httpd package.] ****************************************************************************************************************************************
ok: [192.168.122.50]

TASK [installtaling firewalld] ******************************************************************************************************************************************
ok: [192.168.122.50]

TASK [installtaling mariadb-server] *************************************************************************************************************************************
ok: [192.168.122.50]

TASK [yum] **************************************************************************************************************************************************************
ok: [192.168.122.50]

TASK [yum] **************************************************************************************************************************************************************
ok: [192.168.122.50]

TASK [Friewalld permits http service.] **********************************************************************************************************************************
ok: [192.168.122.50]

TASK [Starting web service.] ********************************************************************************************************************************************
ok: [192.168.122.50]

TASK [Deploying http config.] *******************************************************************************************************************************************
changed: [192.168.122.50]

TASK [ensure httpd is running] ******************************************************************************************************************************************
ok: [192.168.122.50]

RUNNING HANDLER [restart httpd] *****************************************************************************************************************************************
changed: [192.168.122.50]

PLAY [Playbook to test Mylinuxfriend blog working in intranet.] *********************************************************************************************************

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

TASK [connected to intranet...!] ****************************************************************************************************************************************
skipping: [192.168.122.50]

PLAY RECAP **************************************************************************************************************************************************************
192.168.122.50             : ok=12   changed=2    unreachable=0    failed=0  

[root@ansimaster:~/ansiroot/playbook]#

===========================================================
Yeah its good and good to execute, just remove -C and hit the magic button ENTER
===========================================================

No comments:

Post a Comment

kubernetes Pod Scheduling

 ===================   Deployment ================= 1.) Deployment without any nodeName or nodeSelector, pod will spread among all of the av...