Skip to content

Instantly share code, notes, and snippets.

@thomo
Created October 29, 2019 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomo/c73ef4f6cc76ec97a866233512170f39 to your computer and use it in GitHub Desktop.
Save thomo/c73ef4f6cc76ec97a866233512170f39 to your computer and use it in GitHub Desktop.
Solution to using numbered backreference followed by digit in lineinfile
---
- 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