ansible returns with “Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6))

It appears that you don’t have the docker module installed. You will need to install it via your system package manager (apt install python-docker, for example), or using pip (pip install docker). If you have multiple Python versions, make sure that you’ve installed the docker module into the version that Ansible is using.

Force fact-gathering on all hosts

Ansible version 2 introduced a clean, official way to do this using delegated facts (see: http://docs.ansible.com/ansible/latest/playbooks_delegation.html#delegated-facts). when: hostvars[item][‘ansible_default_ipv4′] is not defined is a check to ensure you don’t check for facts in a host you already know the facts about — # This play will still work as intended if called with –limit “<host>” or … Read more

How to get an arbitrary remote user’s home directory in Ansible?

Ansible (from 1.4 onwards) already reveals environment variables for the user under the ansible_env variable. – hosts: all tasks: – name: debug through ansible.env debug: var=ansible_env.HOME Unfortunately you can apparently only use this to get environment variables for the connected user as this playbook and output shows: – hosts: all tasks: – name: debug specified … Read more

Ansible: get current target host’s IP address

A list of all addresses is stored in a fact ansible_all_ipv4_addresses, a default address in ansible_default_ipv4.address. — – hosts: localhost connection: local tasks: – debug: var=ansible_all_ipv4_addresses – debug: var=ansible_default_ipv4.address Then there are addresses assigned to each network interface… In such cases you can display all the facts and find the one that has the value … Read more