Now lets write 1st playbook.
============================
[root@ansimaster ~]# cat apache_playbook.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
[root@ansimaster ~]#
===================================================================
We can check if there is any error in playboot using --sytax-check
===================================================================
[root@ansimaster ~]# ansible-playbook apache_playbook.yml --syntax-check
playbook: apache_playbook.yml
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
===================================================================
If you want to see on how many hosts this playbook will run
===================================================================
[root@ansimaster ~]# ansible-playbook apache_playbook.yml --list-hosts
playbook: apache_playbook.yml
play #1 (webservers): webservers TAGS: []
pattern: [u'webservers']
hosts (1):
192.168.159.142
[root@ansimaster ~]#
===================================================================
Now run your 1st playbook
===================================================================
[root@ansimaster ~]# ansible-playbook apache_playbook.yml
PLAY [webservers] **********************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************
ok: [192.168.159.142]
TASK [Install httpa package] ***********************************************************************************************************
changed: [192.168.159.142]
TASK [Start appache services] **********************************************************************************************************
changed: [192.168.159.142]
PLAY RECAP *****************************************************************************************************************************
192.168.159.142 : ok=3 changed=2 unreachable=0 failed=0
[root@ansimaster ~]#
**** Now go to the client and check httd package should be installed and services should be running *****
[root@web1 ~]# yum list httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.mirrors.estointernet.in
* epel: repos.del.extreme-ix.org
* extras: repos.del.extreme-ix.org
* updates: repos.del.extreme-ix.org
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 Sat 2019-05-04 10:43:22 EDT; 29s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 14664 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─14664 /usr/sbin/httpd -DFOREGROUND
├─14667 /usr/sbin/httpd -DFOREGROUND
├─14668 /usr/sbin/httpd -DFOREGROUND
├─14669 /usr/sbin/httpd -DFOREGROUND
├─14670 /usr/sbin/httpd -DFOREGROUND
└─14671 /usr/sbin/httpd -DFOREGROUND
May 04 10:43:21 web1 systemd[1]: Starting The Apache HTTP Server...
May 04 10:43:22 web1 httpd[14664]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usi... message
May 04 10:43:22 web1 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@web1 ~]#
============================
[root@ansimaster ~]# cat apache_playbook.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
[root@ansimaster ~]#
===================================================================
We can check if there is any error in playboot using --sytax-check
===================================================================
[root@ansimaster ~]# ansible-playbook apache_playbook.yml --syntax-check
playbook: apache_playbook.yml
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
[root@ansimaster ~]#
===================================================================
If you want to see on how many hosts this playbook will run
===================================================================
[root@ansimaster ~]# ansible-playbook apache_playbook.yml --list-hosts
playbook: apache_playbook.yml
play #1 (webservers): webservers TAGS: []
pattern: [u'webservers']
hosts (1):
192.168.159.142
[root@ansimaster ~]#
===================================================================
Now run your 1st playbook
===================================================================
[root@ansimaster ~]# ansible-playbook apache_playbook.yml
PLAY [webservers] **********************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************
ok: [192.168.159.142]
TASK [Install httpa package] ***********************************************************************************************************
changed: [192.168.159.142]
TASK [Start appache services] **********************************************************************************************************
changed: [192.168.159.142]
PLAY RECAP *****************************************************************************************************************************
192.168.159.142 : ok=3 changed=2 unreachable=0 failed=0
[root@ansimaster ~]#
**** Now go to the client and check httd package should be installed and services should be running *****
[root@web1 ~]# yum list httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.mirrors.estointernet.in
* epel: repos.del.extreme-ix.org
* extras: repos.del.extreme-ix.org
* updates: repos.del.extreme-ix.org
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 Sat 2019-05-04 10:43:22 EDT; 29s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 14664 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─14664 /usr/sbin/httpd -DFOREGROUND
├─14667 /usr/sbin/httpd -DFOREGROUND
├─14668 /usr/sbin/httpd -DFOREGROUND
├─14669 /usr/sbin/httpd -DFOREGROUND
├─14670 /usr/sbin/httpd -DFOREGROUND
└─14671 /usr/sbin/httpd -DFOREGROUND
May 04 10:43:21 web1 systemd[1]: Starting The Apache HTTP Server...
May 04 10:43:22 web1 httpd[14664]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usi... message
May 04 10:43:22 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