In Ansible, how do I add a line to the end of a file?

The Ansible discussion group helped get me sorted out on this. The problem is the regexp parameter.

Since I only want the line appended to the file once, I need the regexp to match the line as closely as possible. This is complicated in my case by the fact that my line includes variables. But, assuming the line started [[ -s $HOME/.pythonbrew, I found the following to be sufficient:

- name: Update bashrc for PythonBrew for foo user
  lineinfile:
    dest: /home/foo/.bashrc
    line: "[[ -s ${pythonbrew.bashrc_path} ]] && source ${pythonbrew.bashrc_path}"
    regexp: "^\[\[ -s \\$HOME/\.pythonbrew"
    owner: foo
    state: present
    insertafter: EOF
    create: True

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)