Only check whether a line present in a file (ansible)

Use check_mode, register and failed_when in concert. This fails the task if the lineinfile module would make any changes to the file being checked. Check_mode ensures nothing will change even if it otherwise would. – name: “Ensure /tmp/my.conf contains ‘127.0.0.1’” lineinfile: name: /tmp/my.conf line: “127.0.0.1” state: present check_mode: yes register: conf failed_when: (conf is changed) … Read more

How to continue execution on failed task after fixing error in playbook?

Take a look at Executing playbooks for troubleshooting. If you want to start executing your playbook at a particular task, you can do so with the –start-at-task option: ansible-playbook playbook.yml –start-at-task=”install packages” The above will start executing your playbook at a task named “install packages”. Alternatively, take a look at this previous answer How to … Read more

Ansible notify handlers in another role

You can also call handlers of a dependency role. May be cleaner than including files or explicitly listing roles in a playbook just for the purpose of role to role relationship. E.g.: roles/my-handlers/handlers/main.yml — – name: nginx restart service: > name=nginx state=restarted roles/my-other/meta/main.yml — dependencies: – role: my-handlers roles/my-other/tasks/main.yml — – copy: > src=nginx.conf dest=/etc/nginx/ … Read more

Ansible – accessing local environment variables

I have a Linux vm running on osx, and for me: lookup(‘env’, ‘HOME’) returns “/Users/Gonzalo” (the HOME variable from osx), while ansible_env.HOME returns “/root” (the HOME variable from the vm). Worth to mention, that ansible_env.VAR fails if the variable does not exists, while lookup(‘env’, ‘VAR’) does not fail.

Using Ansible set_fact to create a dictionary from register results

I think I got there in the end. The task is like this: – name: Populate genders set_fact: genders: “{{ genders|default({}) | combine( {item.item.name: item.stdout} ) }}” with_items: “{{ people.results }}” It loops through each of the dicts (item) in the people.results array, each time creating a new dict like {Bob: “male”}, and combine()s that … Read more

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