Monday, August 8, 2016

Ansible – Pull

Most of the Automated engines like Puppet , Chef etc are all Push mode where you will Configure Automation engine to configure other machine over ssh. On other hand Ansible supports Pull mode which runs on the remote host that you wish to configure. Since the remote machine uses the pull option, there is no need to make any connections hence it runs the task much faster.

Ansible pull can be used with couple of situations like,
1. When we want the remote machine to upgrade the code when some thing changes on the repository.
2. Consider you have a large number of machines which need to be configured and the configuration has many number of forks to do. In this case we can use the pull option.

But Pull mode is not suitable in all cases since it
1. It needs credentials if that needs to be connected to other machines.
2. The pull mode doesn't require anything special in your playbooks, but it does require some setup on the nodes you want configured.

Lets write a playbook using Pull option,

[root@puppet centos7]# cat rest.yml
---
- hosts: all
  sudo: yes
  tasks:

   - name: Install git
     yum: name=git state=present
 
   - name: Test My Ansbile Python Module
     git: repo=https://github.com/jagadish12/CounterWebApp.git dest=/tmp/git-stuff 

In the above playbook we can see how to configure checkout git repository by using the pull option.

On running the playbook we can see the output as

[root@puppet centos7]# ansible-playbook rest.yml

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [172.16.202.96]

TASK [Install git] *************************************************************
ok: [172.16.202.96]

TASK [Test My Ansbile Python Module] *******************************************
changed: [172.16.202.96]

PLAY RECAP *********************************************************************
172.16.202.96              : ok=3    changed=1    unreachable=0    failed=0  

We can see the code check out from the repository to the location /tmp/git-stuff.


More to Come , Happy Learning J

No comments :

Post a Comment