how to set an environment variable in ansible ad-hoc command?

1,805 views
Skip to first unread message

Yves Serrano

unread,
Aug 19, 2015, 10:02:19 PM8/19/15
to Ansible Project
Hi there

Is there in ansible a way so set an linux environment variable for a ad-hoc mode and store it permanently in some place?
I tried host_vars, but that doesn't worked. 

I want to run this command:
ansible all -m shell -a "DEBIAN_FRONTEND=noninteractive apt-get upgrade”

without the need to explicit define DEBIAN_FRONTEND and make DEBIAN_FRONTEND=noninteractive the default for the shell module.

I don't want to use a playbook, because normally I run ansible all -m shell -a "apt-get upgrade -s” to see what would be changed, and than 
afterwards to run it without "-s". I often forgot to set  DEBIAN_FRONTEND=noninteractive in the ad-hoc command call. 

I don't want that this the default for the normal environment, when I ssh outside of ansible.

A possible workaround would be if I could recognize an ansible ssh connection from the inside of the host and than set the environment variable accordingly. 
Any idea who to do it?
Or is there a proper ansible way of doing this?

thanks
yves


Brian Coca

unread,
Aug 19, 2015, 10:05:15 PM8/19/15
to Ansible Project
look at .ssh/rc file for setting up vars, but i would also recommend
just using 'ansible -m apt -a "upgrade=yes" '

one of these days i'm just going to patch apt-get to automatically go
non-interactive when stdin is not a tty ....


--
Brian Coca
Reply all
Reply to author
Forward
0 new messages