How to debug Ansible issues?

Debugging modules The most basic way is to run ansible/ansible-playbook with an increased verbosity level by adding -vvv to the execution line. The most thorough way for the modules written in Python (Linux/Unix) is to run ansible/ansible-playbook with an environment variable ANSIBLE_KEEP_REMOTE_FILES set to 1 (on the control machine). It causes Ansible to leave the … Read more

Ansible remote_user vs ansible_user

They both seem to be the same. Take a look here: https://github.com/ansible/ansible/blob/c600ab81ee/lib/ansible/playbook/play_context.py#L46-L55 # the magic variable mapping dictionary below is used to translate # host/inventory variables to fields in the PlayContext # object. The dictionary values are tuples, to account for aliases # in variable names. MAGIC_VARIABLE_MAPPING = dict( connection = (‘ansible_connection’,), remote_addr = (‘ansible_ssh_host’, … Read more

Ansible with_subelements

This is really bad example of how subelements lookup works. (And has old, unsupported, syntax as well). Look at this one: — – hosts: localhost gather_facts: no vars: families: – surname: Smith children: – name: Mike age: 4 – name: Kate age: 7 – surname: Sanders children: – name: Pete age: 12 – name: Sara … Read more

How to set host_key_checking=false in ansible inventory file?

Due to the fact that I answered this in 2014, I have updated my answer to account for more recent versions of ansible. Yes, you can do it at the host/inventory level (Which became possible on newer ansible versions) or global level: inventory: Add the following. ansible_ssh_common_args=”-o StrictHostKeyChecking=no” host: Add the following. ansible_ssh_extra_args=”-o StrictHostKeyChecking=no” hosts/inventory … Read more

How to set environmental variables using Ansible

Yes, there is a cleaner way. You can set environment variables per task: tasks: – shell: echo JAVA_HOME is $JAVA_HOME environment: JAVA_HOME: /usr/java/jre1.8.0_51 register: shellout – debug: var=shellout Output: TASK: [shell echo JAVA_HOME is $JAVA_HOME] ********************************** changed: [localhost] TASK: [debug var=shellout] **************************************************** ok: [localhost] => { “var”: { “shellout”: { “changed”: true, “cmd”: “echo JAVA_HOME … Read more