logo

Openplatform.xyz

Placeholder for our stuff related to Telecom, IT, Internet of things (IOT), ESP8266, Raspberry Pi

Home IOT Telecom IT stuff About Us Contact Us Site Map

Ansible installation in Linux


We will install ansible in a python virtualenv.
virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects.

CentOS7:

Follow this link to install python3.11 on centos7.

Next install virtualenv
[root@superserver Python-3.11.2]# pip3.11 install -U virtualenv --user
Create a virtualenv
[root@superserver Python-3.11.2]# virtualenv ansible-venv
Activate virtualenv and verify python version
[root@superserver Python-3.11.2]# source ansible-venv/bin/activate
(ansible-venv) [root@superserver Python-3.11.2]# which python
/root/Python-3.11.2/ansible-venv/bin/python
Deactivate virtualenv
(ansible-venv) [root@superserver Python-3.11.2]# deactivate
[root@superserver Python-3.11.2]#

Now Install Ansible
# source ansible-venv/bin/activate
# pip3.11 install ansible
# ansible --version
In case you get error
ERROR: Ansible requires the locale encoding to be UTF-8; Detected ISO8859-1.

Solution: Try changing language in Linux GUI "Language Support" and relogin to ssh

Install AWS collection
Ansible has 2 collections for aws
1. community.aws
2. amazon.aws
# ansible-galaxy collection install community.aws
note install directory in output
Installing 'amazon.aws:6.0.0' to '/home/sysadmin/.ansible/collections/ansible_collections/amazon/aws'

In this directory requirements.txt file has additional modules needed. install them with following command
# pip3.11 install -r /home/sysadmin/.ansible/collections/ansible_collections/amazon/aws/requirements.txt
Install amazon.aws collection and its requirements
# ansible-galaxy collection install amazon.aws

Getting started with Ansible:
https://docs.ansible.com/ansible/latest/getting_started/index.html

Ubuntu:

# ansible-galaxy collection install amazon.aws
~$ sudo apt upgrade
~$ sudo apt update
~$ sudo apt-get install openssh-server  (if not installed already)
~$ sudo apt-get update
~$ which python3

~$ sudo apt install python3-virtualenv
~$ virtualenv ansible-venv
~$ source ansible-venv/bin/activate
~$ which python3
~$ deactivate

~$ source ansible-venv/bin/activate
~$ pip3 install ansible
~$ ansible --version
~$ ansible-galaxy collection install community.aws
~$ pip3 install -r /path/of/above/install/requirements.txt
~$ ansible-galaxy collection install amazon.aws
~$ pip3 install -r /path/of/above/install/requirements.txt




How to add option to debug using tags in playbook


# cat test.yaml
---
- name: test tags in playbook
  hosts: localhost
  gather_facts: no

  tasks:

   - name: task1
     debug:
       msg: "Running task1"
     tags: [ 'debug' ]

   - name: task to display debug info
     debug:
       msg: "display debug info when tag is 'debug'"
     tags: ['never', 'debug' ]
The special tag - "never", will prevent a task from running unless a tag is specifically requested.
In above test playbook, the second task will only run when the debug (or never) tag is explicitly requested.



This will run only task1
# ansible-playbook test.yaml

This will run both task1 and task2
# ansible-playbook test.yaml --tags debug

This will run only task2
# ansible-playbook test.yaml --tags never

Playbook examples

Restful API - GET

Restful API - POST

Restful API - DELETE

Standalone BN in AWS

 

Related Pages

Related Links

https://www.youtube.com/watch?v=z-6Ro8hTSgk

https://docs.ansible.com/ansible/latest/collections/amazon/aws/index.html

https://ndubuisi.hashnode.dev/aws-alb-ansible