Ansible and `changed_when` based on `stdout` value

I think you may have misinterpreted what changed_when does. changed_when marks the task as changed based on the evaluation of the conditional statement which in your case is: “command_result.stdout == ‘Ignoring failure…’” So whenever this condition is true, the task will be marked as changed.

Ansible remote templates

You’ve got two options here if your template is going to be on the remote host. Firstly, you can use the fetch module which works as pretty much the opposite to the copy module to bring the template back after cloning the repo on the remote host. A playbook for this might look something like: … Read more

How to nicely split on multiple lines long conditionals with OR on ansible?

Use the YAML folding operator > when: > ansible_user_dir is not defined or ansible_python is not defined or ansible_processor_vcpus is not defined As the ansible documentation states: Values can span multiple lines using | or >. Spanning multiple lines using a Literal Block Scalar | will include the newlines and any trailing spaces. Using a … Read more

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.

How to add spaces at beginning of block in Ansible’s blockinfile?

You can use a YAML feature called “Block Indentation Indicator”: – name: Added a block of lines in the file blockinfile: dest: /path/some_file.yml insertafter: ‘authc:’ block: |2 line0 line1 line2 line3 line4 It’s all about the 2 after the | References: https://groups.google.com/forum/#!topic/ansible-project/mmXvhTh6Omo How do I break a string in YAML over multiple lines? http://www.yaml.org/spec/1.2/spec.html#id2793979 Update: … Read more

How to create a file locally with ansible templates on the development machine

You can delegate tasks with the param delegate_to to any host you like, for example: – name: create some file template: src=~/workspace/ansible_templates/somefile_template.j2 dest=/etc/somefile/apps-available/someproject.ini delegate_to: localhost See Playbook Delegation in the docs. If your playbook should in general run locally and no external hosts are involved though, you can simply create a group which contains localhost … Read more

What do double curly braces ({{) mean in YAML files (as used by Ansible)?

I found this YAML syntax overview in Ansible documantation, to be fairly useful. It says that double curly braces {{ variable }} are used to evaluate expressions. Whilst distinguishing a single curly braces (after a colon), that is used to declare a dictionary. For example: satchmo: {name: Louis Armstrong, music: Jazz, instrument: Trumpet} Also, take … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)