What’s the difference between defaults and vars in an Ansible role?

The Ansible documentation on variable precedence summarizes this nicely: If multiple variables of the same name are defined in different places, they win in a certain order, which is: extra vars (-e in the command line) always win then comes connection variables defined in inventory (ansible_ssh_user, etc) then comes “most everything else” (command line switches, … Read more

ansible: lineinfile for several lines?

You can use the lineinfile built-in in a loop. Here’s an example: – name: Set some kernel parameters   lineinfile:     dest: /etc/sysctl.conf     regexp: “{{ item.regexp }}”     line: “{{ item.line }}”   loop:     – { regexp: ‘^kernel.shmall’, line: ‘kernel.shmall = 2097152’ }     – { regexp: ‘^kernel.shmmax’, line: ‘kernel.shmmax = 134217728’ } … Read more

How to run only one task in ansible playbook?

You should use tags: as documented in https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html If you have a large playbook it may become useful to be able to run a specific part of the configuration without running the whole playbook. Both plays and tasks support a “tags:” attribute for this reason. Example: tasks: – yum: name={{ item }} state=installed with_items: – … Read more

Specify sudo password for Ansible

The docs strongly recommend against setting the sudo password in plaintext: As a reminder passwords should never be stored in plain text. For information on encrypting your passwords and other secrets with Ansible Vault, see Encrypting content with Ansible Vault. Instead you should be using –ask-become-pass on the command line when running ansible-playbook Previous versions … Read more

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