Ticker

6/recent/ticker-posts

How to to install Ansible and debug ansible playbook?

 



Prerequisite:

Make sure you have install python along with pip.

How to install Ansible?

Download the required ansible version from the following URL.
now jump on the server and run the following command.
[pankaj@host]$ pip install ansible-2.9.9.tar.gz
Run pip install with Proxy:
[pankaj@host]$ pip install ansible-2.9.9.tar.gz --proxy http://abc-proxy.domain.com:8080/

Pip command to install dependency which us under requirements.txt file.
[pankaj@host]$ pip install -r requirements.txt --proxy http://abc-proxy.domain.com:8080/
Run pip install with Proxy

Install ansible with nexus Pypi repo type:

Sometime when you are working in Production environment you don't have proxy or internet there instead you might be using some artifact management like nexus or Jfrog.

You can configure of Pypi type repository in pip configuration file so that pip will try to look into this configured repo for any artifact that you are trying to install via pip

[pankaj@host]$ cat /etc/pip.conf
[global]
default-timeout = 60
respect-virtualenv = true
downlaod-cache = /tmp
log-file = /tmp/pip-log.txt
trusted-host = mytestnexus
index = http://username_nexus:password_nexus@mytestnexus:8081/repository/PyPi-All/pypi
index-url = http://username_nexus:password_nexus@mytestnexus:8081/repository/Pypi-All/simple

Dubbugging:

  • Adding -vvvv parameter to the ansible/ansible-playbook command will display the debugging information for the playbook. Example : 
    • [pankaj@host]$ ansible-playbook -i hosts playbook-name -vvv
  • You can use debug module of Ansible to print the message on stdout.
- name: Check Ansible version for debugging purpose 
  command: ansible --version 
  register: ansibleVersionVar

- name: Print version in debug mode
  debug:
    msg: "Ansible Version is ->: {{ ansibleVersionVar.stdout }}"

That's all for this blog!!
Will keep adding.

Post a Comment

0 Comments