Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

MASTER & SLAVE:

sudo su -

yum update

amazon-linux-extras install epel

yum install ansible

ansible --version

useradd ansadmin
passwd ansadmin

visudo
ansadmin ALL=(ALL) NOPASSWD: ALL

cd /etc/ssh/
vi sshd_config

service sshd restart

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------

MASTER:

sudo su - ansadmin

ssh-keygen
ssh-copy-d IP(SLAVE)
ssh IP(should not ask for pwd)

sudo vi /etc/ansible/hosts
[web_servers]
IP(SLAVE)

ansible all -m ping


get success for SLAVE machine

cat > hello.html


Hello World!

ansible all -m copy -a "src=/home/ansadmin/hello.html dest=/home/ansadmin" ->


copies filr from src to slave destination path
ansible all -m copy -a "src=/home/ansadmin/hello.html dest=/home/ansadmin" -> does
not copy as the file already exists

ansible all -m yum -a "name=httpd state=latest" -> does not install http on SLAVE
as it does not have httpd access
ansible -b all -m yum -a "name=httpd state=latest" -> installs httpd in slave (b by
default root user)
ansible -b all -m yum -a "name=httpd state=started" -> starts httpd in slave

SLAVE: service httpds status

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------

JENKINS:

plugin - install 'Publish over SSH'


Manage Jenkins - Configuare - Publish Over SSH ----> Here add UN & PWD details of
the ansible servers

Build Configure - Post Build Action -


SSH Over: ansible_server
Source: webapp/target/*.war -> this copies from jenkins workspace
Remote Dir(ansible_server): //home//ansadmin//playbooks -> to this path in
ansible
exce Command: ansible-playbook /home/ansadmin/playbooks/copyfile.yml ------->
command to run the playbook

ANSIBLE:

/home/ansadmin/playbooks/ - copyfile.yml

---
- hosts: web-servers ----------------> (this is the one that is defines in
/etc/ansible/hosts and connects to tomcat server)
become: true
tasks:
- name: copy war onto tomcat servers
copy:
src: /home/ansadmin/playbooks/webapp/target/webapp.war
dest: /home/ansadmin/tomcat/

You might also like