Table of Contents

Install Ansible

NOTE: This install guide is is meant for adding Ansible to Centos6.

Login the NetYCE terminal and execute the following steps.

Install Python 2.7

sudo yum update
cd /tmp
sudo wget https://www.python.org/ftp/python/2.7.16/Python-2.7.16.tgz
sudo tar xzf Python-2.7.16.tgz
cd Python-2.7.16
sudo ./configure --enable-optimizations
sudo make altinstall
sudo /usr/local/bin/python2.7 -V
sudo ln -s /usr/local/bin/python2.7 /usr/bin/python2.7
sudo rm /tmp/Python-2.7.16 -R
sudo rm /tmp/Python-2.7.16.tgz

Install Pip

sudo curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
sudo /usr/local/bin/python2.7 get-pip.py

Install Netconf plugins/libs

sudo yum install libxslt
sudo yum install libxml2
sudo /usr/local/bin/pip install ncclient
sudo /usr/local/bin/pip install jxmlease

Install Ansible

sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
sudo yum update
sudo yum install ansible -y
ansible --version

Ansible EXAMPLE Template

Template name: ansible_reachable_test

Required variables to let ansible work with python 2.7:

- name: check reachable hosts
  hosts: all
  gather_facts: no
  vars:
    ansible_python_interpreter: /usr/local/bin/python2.7
    cli:
      username: <Rme_user>
      password: <Rme_passwd>
  tasks:
    - command: ping -c1 \{\{ inventory_hostname \}\}
      delegate_to: localhost
      register: ping_result
      ignore_errors: no
    - group_by: key=reachable
      when: ping_result|success

Ansible Scenario

Ansible_cmd_job

Description <node> Ansible Playbook job

# Test whether node is live and reachable
Reachable -n <node>
if <error>
     Log_action -n <node> -a Ansible_job -m "<node> is not Reachable"
    stop
endif
Log_action -n <node> -a Ansible_job -m "<node> is Reachable"

# Create ansible yml file
config_create -n <node> -t <template> -f <node>.yml

# Execute ansible command job
ansible_exec -n <Node_fqdn> -s <node>.yml -a "-vvvv"
if <error>
    Log_action -n <node> -a Ansible_job -m "Failed executing commands"
    stop
endif
Log_action -n <node> -a Ansible_job -m "Completed executing commands"

Ansible Commandjob

Commands:

# View your template
{<ans_template>}

Scenario:

[parameters]
template = ansible_reachable_test


[scenario]
Description <node> Ansible command job...
task = Ansible_cmd_job

end