6

I have an ansible playbook with different roles. In each role I would like to add several lines to the same configuration file. For example, adding sections to a ini file:

[section]
param1=value1
param2=value2

What would be the best way to accomplish this?

Is it possible to concatenate template pieces? For example:

[section]
param1={{ value_var1 }}
param2={{ value_var2 }}

1 Answer 1

3

By your example i would do like this

- name: Checking is applied aleady
  shell: grep "ANSIBLE_ROLE_X_APPLIED" /path/to/file
  ignore_errors: yes
  register: grep_role_x_applied

- name: Applying changes in file
  lineinfile: dest=/path/to/file line='{{ item }}'
  when: grep_role_x_applied.stdout == ""
  with_items:
    - '; ANSIBLE_ROLE_X_APPLIED'
    - '[section]'
    - 'param1=value1'
    - 'param2=value2' 

Of course in each role you have diferent tags like ANSIBLE_ROLE_X_APPLIED

Or something based on this idea

EDIT: If this is really ini file - i better play with ansible core module ini_file

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .