How to do multiline shell script in Ansible

Ansible uses YAML syntax in its playbooks. YAML has a number of block operators: The > is a folding block operator. That is, it joins multiple lines together by spaces. The following syntax: key: > This text has multiple lines Would assign the value This text has multiple lines\n to key. The | character is … Read more

How to switch a user per task or set of tasks?

With Ansible 1.9 or later Ansible uses the become, become_user, and become_method directives to achieve privilege escalation. You can apply them to an entire play or playbook, set them in an included playbook, or set them for a particular task. – name: checkout repo git: repo=https://github.com/some/repo.git version=master dest={{ dst }} become: yes become_user: some_user You … Read more

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

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