Hello,
I have a script file with 40-50 variables (some are something like this:
ENV=`hostname | awk -F- '{print $1}' | sed 's/ACE//'`) and I deploy this
file to all my machines in /etc/profile.d/some_script.sh
I created a new user with which I only run deployments with ansible and
have modified the /etc/sudoers file like this:
Defaults !env_reset #notice the "!" this does not allow sudo to reset
the env. This way when I run something with sudo I don't lose environment
variables
ansible ALL=(ALL) NOPASSWD: ALL
Something goes wrong with the command below I can see the env variables
[ansible@ACEPR-ANSIREBOND-01 ansible]$ ansible ACEPP-LM-01 -m setup | grep
ENV
"ENV": "PP",
"ENV_PROP": "preprod",
"ENV_PROP_PREFIX": "preprod",
But when I run this playbook:
- name: prereq
hosts: ACEPP-LM-01
remote_user: ansible
sudo: True
tasks:
- shell: echo {{ ansible_env.ENV }}
It gives error: fatal: [ACEPP-LM-01] => One or more undefined variables:
'dict' object has no attribute 'ENV'
Why is ansible seeing the env variables (gathering_facts is ok) but it
can't resolve {{ ansible_env.ENV }}
[ansible@ACEPP-LM-01 ~]$ sudo echo $ENV
PP
[ansible@ACEPP-LM-01 ~]$ env | grep ENV
ENV=PP
ENV_PROP=preprod
ENV_PROP_PREFIX=preprod
With root and no sudo everything is ok. Is it the sudo ?
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/fe3bca85-25df-4d02-b95b-46c14bf81498%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.