3

I'm using ansible-playbook to deploy my django application to Ubuntu servers. I'm storing my django environment variables in .bashrc file of the user ubuntu in the server. But my ansible-playbook is not using the env variables in .bashrc even when i'm running as ubuntu user. Is there any way for me to access these env variables using ansible-playbook.

4
  • 2
  • @techraf i'm having issues with accessing the values that i add in .bashrc when i run some commands using ansible. I can add the values but ansile-playbook is not using these values when i run some commands. – Nijo Aug 19 '17 at 10:03
  • 2
    Of course you have, because bash does not read .bashrc in non-interactive mode. – techraf Aug 19 '17 at 10:05
  • @techraf then how can i run django management commands in ansible using the variables in .bashrc – Nijo Aug 19 '17 at 13:21
2

I use this one:

  - shell: . ~/.bashrc  && echo $LS_COLORS
    args: 
      executable: /bin/bash
    register: result

  - set_fact:
      ls_colors: "{{ result.stdout }}"
0

This also works so your code looks cleaner

- name: Use ruby 2.6.6
  shell: |
    source ~/.bashrc
    rvm use 2.6.6
    gem install fastlane

- name: Use ruby 2.6.6
  shell: |
    source ~/.bash_profile
    rvm use 2.6.6
    gem install fastlane

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.