Conflicting action statement in ansible

Here is the problem, you have mixed up two tasks into one: — – hosts: webhost sudo: yes connection: ssh tasks: – name: debuging module shell: ps aux register: output – name: show the value of output debug: var=output And out put of the playbook will be like this: PLAY [all] ********************************************************************* TASK [setup] ******************************************************************* … Read more

How to compare kernel, software, etc. versions numbers in Ansible?

There is a version test for it: {{ ansible_distribution_version is version(‘12.04’, ‘>=’) }} {{ sample_version_var is version(‘1.0’, operator=”lt”, strict=True) }} Prior to Ansible 2.5, all tests were also provided as filters, so, the same was achievable with a filter, named version_compare, but in current versions of Ansible, the test was renamed and, overall, the tests … Read more

Formatting stdout in a debug task of Ansible

Try this option. You’ll love it. There’s a new YAML callback plugin introduced with Ansible 2.5 — meaning any machine running Ansible 2.5.0 or later can automatically start using this format without installing custom plugins. To use it, edit your ansible.cfg file (either globally, in /etc/ansible/ansible.cfg, or locally in your playbook/project), and add the following … 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 can I check if a string exists in a file?

It’s a tricky one. the lineinfile module is specifically intended for modifying the content of a file, but you can use it for a validation check as well. – name: find lineinfile: dest: /etc/passwd line: “user” check_mode: yes register: presence failed_when: presence.changed check_mode ensures it never updates the file. register saves the variable as noted. … Read more

tech