Static Inventory and configure ansible machine

hosts file in /etc/ansible/hosts or with option -i hosts


other possible configuration for hosts file

#this is the inventory for machine

and run with

ansible shortname -m ping -u cloud_user

Inventory alias

you need to have in the inventory localhost

sudo vim /etc/ansible/hosts
ec2 ansible_host=myipaddress or dns

setup of ansible user

sudo useradd ansible
mkdir ~/.ssh
sudo su - ansible
echo "ssh-rsa my ansible public key ansible@ip" >> ~/.ssh/authorized_keys
chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Dynamic Inventory

you need to have these 2 files, the .py must be executable

ll ec2.*
-rw-rw-r-- 1 ansible ansible   471 Dec  4 09:40 ec2.ini
-rwxrwxr-x 1 ansible ansible 73130 Dec  3 14:23*


--- #only for testing
- hosts: all
  - shell: ls -l /home
    register: ls_contents
  - debug:
      msg: "LS output: {{ ls_contents }}"

how to apply

ansible-playbook -i ls.yml
ansible all -i -m shell -a "echo a"


Maybe I'll check in the future

Some commands and playbook

#print some ansible facts
ansible machine -m setup 

#start an httpd service
ansible machine -b -m service -a "name=httpd state=started"

#use not default playbook
ansible-playbook -i not-default-inventory myplaybook.yml 

#filter the ansible facts
ansible machine -m setup -a filter-*ipv4*

vim /home/ansible/git-setup.yml

--- # install git on target host
- hosts: workstation
  become: yes
  - name: install git
      name: git
      state: latest

Save and exit the file (:wq in vim).

Run the playbook:

ansible-playbook -i /home/ansible/inventory /home/ansible/git-setup.yml

do a module ping of my machine

ansible all -i -m ping


my installation script

apt install software-properties-common
apt-add-repository ppa:ansible/ansible
apt update -y
apt upgrade -y 
apt install ansible -y
ansible --version
sudo adduser ansible
passwd -d ansible

apt install python-pip -y

pip install docker
apt install nodejs -y
apt install npm -y
service docker status

#apt install docker-compose #this will crash the system. 
pip install docker-compose

git clone
ansible-playbook -i inventory -e docker_registry_password=password install.yml

Tower Dynamic Inventory and multiple ssh keys

Custom Environment

  • Until you haven't active you don't see it in the web interface the option.

they said to use PATCH method to load but I'm not sure it is necessary probably it is enough enabled from the installation playbook.

A guy declare if you create the environments in the /var/lib/awx/venv/ansible/ you don't need to modify the playbook installation.

Run everything from the webconsole so you can see the error and fix it.

grep custom_venv_dir inventory

ansible-playbook -i inventory install.yml --extra-vars "@venv_vars.yaml"

at this point with the http://localhost:8080/api/v2/config/
and at the end you will have the 

"custom_virtualenvs": [


Salvo diversa indicazione, il contenuto di questa pagina è sotto licenza Creative Commons Attribution-ShareAlike 3.0 License