Created
October 29, 2019 22:20
-
-
Save thomo/c73ef4f6cc76ec97a866233512170f39 to your computer and use it in GitHub Desktop.
Solution to using numbered backreference followed by digit in lineinfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
tasks: | |
- name: create file | |
copy: src=./demo dest=/tmp/demo | |
# not working as expected | |
- name: update xxxx | |
lineinfile: | |
dest: /tmp/demo | |
regexp: '^(.*)xxxx' | |
line: '\1{{ansible_date_time.year}}' | |
backrefs: yes | |
state: present | |
- name: update yyyy | |
lineinfile: | |
dest: /tmp/demo | |
regexp: '^(?P<group>.*)yyyy' | |
line: '\g<1>{{ansible_date_time.year}}' | |
backrefs: yes | |
state: present | |
- name: update zzzz | |
lineinfile: | |
dest: /tmp/demo | |
regexp: '^(?P<group>.*)zzzz' | |
line: '\g<group>{{ansible_date_time.year}}' | |
backrefs: yes | |
state: present |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment