Skip to content

Replace string in file using matchpattern spec #1530

Answered by bngameni
bngameni asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @olblak,

  role_variables_change:
    name: Update role variables
    kind: file
    scmid: gitlab
    sourceid: role_vars
    spec:
      files:
        - "inventory/group_vars/apache/main.yml"
      matchpattern: "(?m)^apache2_"
      replacepattern: "apache_"
    

We applied the (?m) pattern to achieve multiline matching, and it effectively resolved the issue.

We realized that the "^apache2" pattern was only attempting to match the first line, which caused errors on our end.

After carefully studying the golang expression, we identified the correct regular expression to use.

Replies: 4 comments 8 replies

Comment options

You must be logged in to vote
7 replies
@bngameni
Comment options

@olblak
Comment options

@olblak
Comment options

@bngameni
Comment options

Answer selected by dduportal
Comment options

You must be logged in to vote
1 reply
@bngameni
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants