Actually, it finally struck me what the regexp should really be since I only want one copy of the line in the file:
name: Update bashrc for PythonBrew for foo user
lineinfile:
dest=/home/foo/.bashrc
line=‘[[ -s ${pythonbrew.bashrc_path} ]] && source ${pythonbrew.bashrc_path}’
regexp=‘^[[ -s’
state=present
insertafter=EOF
create=True
I’d like to match the whole line in the regexp param, but with the variable expansion, not sure how it would be done. In this case, the truncated regexp should be sufficient. Hopefully.
FYI, I wouldn’t recommend asking Ansible questions on SO.
It divides the community and most folks are here – mainly I just don’t like SO’s policy on closing questions and not wanting to have discourse/conversation. I understand why they do it, but just don’t personally prefer it.
Tim and company do read SO, but you’ll get an answer here a lot faster.
adding as the regexp one matching the line - or just part of it- to be inserted is much better.
I have such cases too but answered too fast …
the variables {{ variable }} will be expanded in the rexgep string
but depending on their contents they might need quoted. For example to avoid the ‘.’ being interpreted by the regexp engine