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
--
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/f212092b-468a-b7c7-1f5d-8681e1a235fd%40olstad.com.
For more options, visit https://groups.google.com/d/optout.