Saturday, May 4, 2019

Managing config from ansible server to client and then do conditional restart of service



[root@ansimaster conf]# cat /root/apache_playbook2.yml
---
- hosts: webservers
  become: true
  become_user: root
  tasks:
  - name: Install httpa package
    yum: name=httpd state=present
  - name: Start appache services
    service: name=httpd state=started
  - name: Deploying httpd conf
    copy: src=/ansible/config/httpd/conf/ dest=/usr/share/httpd/noindex/
    notify: restart httpd
  handlers:
  - name: restart httpd
    service: name=httpd state=restarted


#notify module executed only if file get copied to target host only and then restart httpd

[root@ansimaster conf]#

[root@ansimaster conf]# diff index.html index.html.bkp
68c68
<         <h1> Welcome mylinuxfriends 123..</h1>  <=========== we have added new contents in config.
---
>         <h1> Testing 123..</h1>
[root@ansimaster conf]#

[root@ansimaster conf]# ansible-playbook /root/apache_playbook2.yml <======== run your playbook


**** Now go to your client and check new content should be copied to target nodes and httpd should be running ****

[root@web1 images]# grep -i welcome /usr/share/httpd/noindex/index.html
          <h1> Welcome mylinuxfriends 123..</h1>
                                        <p>To prevent this page from ever being used, follow the instructions in the file <tt>/etc/httpd/conf.d/welcome.conf</tt>.</p>
[root@web1 images]#
[root@web1 images]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-05-04 12:31:30 EDT; 20min ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 23862 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 23866 (httpd)
   Status: "Total requests: 5; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─23866 /usr/sbin/httpd -DFOREGROUND
           ├─23868 /usr/sbin/httpd -DFOREGROUND
           ├─23869 /usr/sbin/httpd -DFOREGROUND
           ├─23870 /usr/sbin/httpd -DFOREGROUND
           ├─23871 /usr/sbin/httpd -DFOREGROUND
           ├─23872 /usr/sbin/httpd -DFOREGROUND
           ├─23882 /usr/sbin/httpd -DFOREGROUND
           ├─23883 /usr/sbin/httpd -DFOREGROUND
           └─23884 /usr/sbin/httpd -DFOREGROUND

May 04 12:31:30 web1 systemd[1]: Starting The Apache HTTP Server...
May 04 12:31:30 web1 httpd[23866]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usi... message
May 04 12:31:30 web1 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@web1 images]#

No comments:

Post a Comment

kubernetes Pod Scheduling

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