On 10. sep. 2017 20:50, Ehab Aboudaya wrote:
> i am trying to get the controller ip address that is used to run the
> playbook.
> The ip is the one when the ssh connection establishes to remote.
>
> debug: msg="{{ (ansible_env|default({})).SSH_CLIENT|default('')}}"
>
> the SSH_CLIENT in my case is always empty. yes, i have gather facts and
> still empty.
Thats because SSH_CLIENT is not a fact so your default filter is kicking in.
> i have to workaround this by
>
> - name: Get the IP of the controller
> shell: "ss -4 -ntp 2> /dev/null | head -2 | grep sshd | awk '{print
> $4}' | awk -F: '{print $1}'"
> ignore_errors: yes
> no_log: yes
> register: ssh_ip
>
> but this is not reliable because there can be other users connected and the
> above only gets the first item
>
> any help is appreciated, thanks in advance
You could use delegated_facts
https://docs.ansible.com/ansible/latest/playbooks_delegation.html#delegated-facts
--
Kai Stian Olstad