==================================================
Playbook to install package and start services
==================================================
[root@ansimaster playbooks]# cat installpackage.yml
#Simple Ansible playbook
-
name: Play 1
hosts: webservers
tasks:
- name: Install httpd package on webservers
yum:
name: httpd
state: present
- name: Start web service
service:
name: httpd
state: started
[root@ansimaster playbooks]#
[root@ansimaster playbooks]#
[root@ansimaster playbooks]# ansible-playbook installpackage.yml --syntax-check
playbook: installpackage.yml
[root@ansimaster playbooks]#
[root@ansimaster playbooks]#
[root@ansimaster playbooks]# ansible-playbook installpackage.yml
PLAY [Play 1] **************************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************
ok: [192.168.159.142]
TASK [Install httpd package on webservers] *********************************************************************************************
changed: [192.168.159.142]
TASK [Start web service] ***************************************************************************************************************
changed: [192.168.159.142]
PLAY RECAP *****************************************************************************************************************************
192.168.159.142 : ok=3 changed=2 unreachable=0 failed=0
[root@ansimaster playbooks]#
===================================================
On Clint side httpd status before running playbook
===================================================
[root@web1 ~]# yum list httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.nbrc.ac.in
* epel: sg.fedora.ipserverone.com
* extras: mirror.nbrc.ac.in
* updates: mirror.nbrc.ac.in
Available Packages
httpd.x86_64 2.4.6-89.el7.centos updates
[root@web1 ~]#
[root@web1 ~]#
[root@web1 ~]# systemctl status httpd
Unit httpd.service could not be found.
[root@web1 ~]#
===================================================
On Clint side httpd status after running playbook
===================================================
[root@web1 ~]# yum list httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.nbrc.ac.in
* epel: sg.fedora.ipserverone.com
* extras: mirror.nbrc.ac.in
* updates: mirror.nbrc.ac.in
Installed Packages
httpd.x86_64 2.4.6-89.el7.centos @updates
[root@web1 ~]#
[root@web1 ~]# 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 Fri 2019-05-24 12:04:32 EDT; 9s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 7994 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─7994 /usr/sbin/httpd -DFOREGROUND
├─7995 /usr/sbin/httpd -DFOREGROUND
├─7996 /usr/sbin/httpd -DFOREGROUND
├─7997 /usr/sbin/httpd -DFOREGROUND
├─7998 /usr/sbin/httpd -DFOREGROUND
└─7999 /usr/sbin/httpd -DFOREGROUND
May 24 12:04:32 web1 systemd[1]: Starting The Apache HTTP Server...
May 24 12:04:32 web1 httpd[7994]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usin... message
May 24 12:04:32 web1 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@web1 ~]#
No comments:
Post a Comment