3

I'm relatively new to ansible, so apologies if this question misses something.

My goal is to add a line to the ~/.bashrc file with ansible. I think the best way to do that is with the ansible.builtin.lineinfile module.

Unfortunately, I've run the module, it appears to run properly on the target host machine, reports back 'changed' on the first run (and 'ok' on subsequent runs), but no changes are actually made in the ~/.bashrc file.

Appreciate any help in figuring out what changes would be needed to create the desired outcome.

---

- hosts: setup
  become: true
  vars_files:
    - /etc/ansible/vars.yml

  tasks:
    - name: Test lineinfile
      ansible.builtin.lineinfile:
        path: ~/.bashrc
        line: "test lineinfile"

2 Answers2

3

Changed path: ~/.bashrc to path: .bashrc and it worked.

1

Multiple lines could be done this way:

    - name: Add an environment variable to the remote user's shell.
      lineinfile:
        dest: "~/.bashrc"
        line: |
            Line 1
            Line 2
Clubman
  • 81
  • 1
  • 3