Step 1) Copy ssh keys to remote target server.
[osboxes@master ansible-projects]$ ssh-copy-id webserverhost02
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/osboxes/.ssh/id_rsa.pub"
The authenticity of host 'webserverhost02 (192.168.1.246)' can't be established.
ECDSA key fingerprint is SHA256:QYhfRimq4gvWwsjg+kul52yjv48WfbcRHaaKgSuUQeE.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
osboxes@webserverhost02's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'webserverhost02'"
and check to make sure that only the key(s) you wanted were added.
Step 2) Execute ansible ping module to check the remote server connectivity
[osboxes@master ansible-projects]$ ansible all -m ping -i webserver-inventory.txt
webserverhost02 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
Step 2) Verify the syntax check before running actual playbook.
[osboxes@master ansible-projects]$ ansible-playbook install_configure_apache.yml -i webserver-inventory.txt --syntax-check
playbook: install_configure_apache.yml
Step 3) I have created a playbook for apache webserver installation and instance creation. You may download the source code from github repository.
[osboxes@master ansible-projects]$ cat install_configure_apache.yml
---
- hosts: all
become: yes
become_method: sudo
roles:
- role: "roles/apache24"
[osboxes@master ansible-projects]$ cat webserver-inventory.txt
webserverhost02
[osboxes@master roles]$ tree apache24/
apache24/
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── README.md
├── tasks
│ ├── boot.yml
│ ├── filesystem.yml
│ ├── install-dependencies.yml
│ ├── install.yml
│ ├── main.yml
│ └── validate.yml
├── templates
│ ├── apache.service.j2
│ └── httpd.conf.j2
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml
8 directories, 15 files
Step 3) Run Ansible playbook for apache installation from source and instance creation.
[osboxes@master ansible-projects]$ ansible-playbook install_configure_apache.yml -i webserver-inventory.txt
PLAY [all] **************************************************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************
ok: [webserverhost02]
TASK [roles/apache24 : check if the apache instance already present] ****************************************************************************************
ok: [webserverhost02]
TASK [roles/apache24 : fail] ********************************************************************************************************************************
skipping: [webserverhost02]
TASK [roles/apache24 : create a directory for apache binaries location] *************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : create a directory for apache instance location] *************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : create a directory for apache log location] ******************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Install all the packages] ************************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Download apache binaries] ************************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Download apr binaries] ***************************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Download apr-util binaries] **********************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Install httpd package] ***************************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Create a symlinks for apache products] ***********************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Install apr package] *****************************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Copy apr package to srclib] **********************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Install apr-util package] ************************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Copy apr-util package to srclib] *****************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Create a symlinks for python] ********************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Source code compilation] *************************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Remove symlink] **********************************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Configure Apache and change the desired installation location] ***********************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Execute the make command to prepare the files for the installation of Apache] ********************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Execute make install command to install apache] **************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : delete log directory] ****************************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Create a log symlinks] ***************************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : deploy httpd.conf.j2 to /home/osboxes/instances/apache24/poc-apache-instance/conf/] **************************************************
changed: [webserverhost02]
TASK [roles/apache24 : cleanup apache downloads] ************************************************************************************************************
changed: [webserverhost02] => (item=httpd-2.4.46.tar.gz)
changed: [webserverhost02] => (item=apr-1.7.0.tar.gz)
changed: [webserverhost02] => (item=apr-util-1.6.1.tar.gz)
TASK [roles/apache24 : Change the ownership for apache products directory] **********************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : Change the ownership for apache instances directory] ********************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : deploy apache.service.j2 to /etc/systemd/system/apache.service] **********************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : load apache service] *****************************************************************************************************************
changed: [webserverhost02]
TASK [roles/apache24 : enable apache service] ***************************************************************************************************************
ok: [webserverhost02]
TASK [roles/apache24 : starting the apache instance] ********************************************************************************************************
changed: [webserverhost02]
PLAY RECAP **************************************************************************************************************************************************
webserverhost02 : ok=31 changed=28 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
[osboxes@master ansible-projects]$
Step 4) Verify apache instance status on remote host
[osboxes@webserverhost02 ~]$ ps -ef | grep httpd
osboxes 63796 1 0 08:37 ? 00:00:00 /home/osboxes/instances/apache24/poc-apache-instance/bin/httpd -k start
osboxes 63797 63796 0 08:37 ? 00:00:00 /home/osboxes/instances/apache24/poc-apache-instance/bin/httpd -k start
osboxes 63798 63796 0 08:37 ? 00:00:00 /home/osboxes/instances/apache24/poc-apache-instance/bin/httpd -k start
osboxes 63799 63796 0 08:37 ? 00:00:00 /home/osboxes/instances/apache24/poc-apache-instance/bin/httpd -k start
[osboxes@webserverhost02 poc-apache-instance]$ curl -k http://webserverhost02:10001
<html><body><h1>It works!</h1></body></html>
[osboxes@webserverhost02 poc-apache-instance]$
Great Post Pavan.
ReplyDeleteThank you.
ReplyDeletesalesforce online course
ReplyDeletehadoop online course
Data Science online course
linux online course
etl testing online course
web methods online course
business analyst training
oracle adf training