Update bashrc with virtualenv info using Ansible

Question:

I have a python virtualenv running on a remote server. I am trying to update the bashrc of the remote server with the following info using Ansible.

Is there any way to accomplish this using Ansible?

Answer:

  1. Use Ansible blockinfile module to maintain the lines in the .bashrc or /etc/bashrc:
  2. Or better: create a .bashrc.d (or .bash_profile.d) directory, replace your .bashrc with a call to source all files in the directory:

    and add the above commands as a separate file. Move other commands from the current .bashrc to another file and place it in .bashrc.d directory.

    This you can easily achieve with file and copy modules in Ansible.

Leave a Reply