Get shell environment variables on target after going thru a bastion

I access a target host thru a bastion server which requires a Yubikey password. I have setup ssh keys so I can access the target host without a password prompt once the authenticated socket on the bastion is cached. When I run setup against the target host, none of the specific environment variables setup via .bashrc on that target host appear.

Here’s a snippet of my ~/.ssh/config to show how I access the target::

Host xx
Hostname xxname.example.com
Host xxdb*
ProxyCommand ssh -q xx -W %h:%p

The environment variables I’m after are on the xxdb02 server (via ssh xxdb02) under a Linux account which owns the vendor software I’m trying to manage. These environment variables vary by host. Rather than recreate this data in yml I want to pick up what’s already defined in the target host account. To no avail I’ve played around with the environment key word and with shell commands to pickup these variables.

There must be a better way. Please cure me of my cluelessness.

AtDhVaAnNkCsE

if gather_facts are run on the target server, the hash {{ ansible_env }} should have some environment variables.
also the ansible ssh connection doesnt invoke a login shell so .bashrc scripts wouldnt not be run . if you use sudo and set -i flag in sudo_flags in ansible.cfg a login shell would be invoked and i think bashrc woudl be run.

  • Benno

No, I’m afraid the -i flag does not make a difference.

I’m trying to avoid a shell hack and it just seems really basic that we should have easy access to the environment variables of the target login account.