Use case: adding bash-completion to dev-environment playbook.
In OSX, I need to write to either .profile
or .bash_profile
via Ansible. I need to add some config lines to one of those files and would like to do so to whichever one exists. I need to add those lines to the first of those files that exists since OSX looks for .bash_profile
, .bash_login
, then .profile
and stops looking when it finds one of them.
Is there an environment variable I can use to determine which file was used to load the bash config?
Is there a way to create a variable in Ansible that tells Ansible which of those files to write to, depending on the first one in the list (.bash_profile
, .bash_login
, .profile
) that exists?
I've tried this in my existing playbook.yml
, which does not overwrite my initially stated var of "bash_config":
- hosts: localhost
connection: local
vars:
bash_config: "{{ ansible_user_dir }}/.profile"
tasks:
- stat: path="{{ ansible_user_dir }}/.profile"
register: bash_config
when: bash_config.exists = true
- stat: path="{{ ansible_user_dir }}/.bash_login"
register: bash_config
when: bash_config.exists = true
- stat: path="{{ ansible_user_dir }}/.bash_profile"
register: bash_config
when: bash_config.exists = true