Question:
I would expect this to be pretty simple. I’m using the lineinfile
module like so:
1 2 3 4 5 6 7 8 9 10 11 |
- name: Update bashrc for PythonBrew for foo user lineinfile: dest=/home/foo/.bashrc backup=yes line="[[ -s ${pythonbrew.bashrc_path} ]] && source ${pythonbrew.bashrc_path}" owner=foo regexp='^' state=present insertafter=EOF create=True |
The problem I’m having is that it’s replacing the last line in the file (which is fi
) with my new line rather than appending the line. This produces a syntax error.
Do I have the parameters correct? I’ve tried setting regexp to both '^'
and ''
(blank). Is there another way to go about this?
I’m using Ansible 1.3.3.
Answer:
Apparently ansible has matured and now (version >2.4.0) according to the documentation, The defaults when only the line is specified will append a given line to the destination file:
1 2 3 4 5 6 |
- name: Update bashrc for PythonBrew for foo user lineinfile: dest: /home/foo/.bashrc line: "[[ -s ${pythonbrew.bashrc_path} ]] && source {pythonbrew.bashrc_path}" owner: foo |