Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: append a string to an existing line in a file

Tags:

ansible

I am using ansible module to edit the manifest file for kube-apiserver

    - --feature-gates=AdvancedAuditing=true

I want to append new feature-gate like

    - --feature-gates=AdvancedAuditing=true,TTLAfterFinished=true

I tried many thing, one of which -

- name: append TTLAfterFinished to existing list of feature-gates
  lineinfile:
    path: item.0.item.file_path
    backrefs: yes
    regexp: "^(.*feature-gates.*)$"
    line: '\1,TTLAfterFinished=true'

With no luck.. :( Any help ?

like image 250
Prakash Ashok Dumbre Avatar asked Oct 15 '22 15:10

Prakash Ashok Dumbre


1 Answers

What you have worked fine for me, but I do not have an item varaible. So I have this:

- name: append TTLAfterFinished to existing list of feature-gates
  lineinfile:
    path: "{{ role_path }}/files/file_path"
    backrefs: yes
    regexp: "^(.*feature-gates.*)$"
    line: '\1,TTLAfterFinished=true'

Perhaps it is your item variable that is the problem.

like image 187
Jack Avatar answered Oct 20 '22 13:10

Jack