I get ssh connection from fact variable in fact.

my code in template (get-ip.j2):

nod= {{ ansible_env.SSH_CONNECTION }}

my output is :

nod= 55414 22

Now, how can I separator from this?

1 Answer 1


Before getting into the answer, I recommend using stackoverflow for Ansible/Jinja2 questions. There's a lot of questions already answered there.

Now, as for your question: Split the string on space and then extract the third element:

{{ansible_env.SSH_CONNECTION.split(' ')[2]}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.