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:


What would be the best way to accomplish this?

Is it possible to concatenate template pieces? For example:

param1={{ value_var1 }}
param2={{ value_var2 }}

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 == ""
    - '[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

| improve this answer | |

What about

cat file1 file2 file3 > targetFile


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.