0

I need to set variable in defaults\main.yml to something like:

eth1_ipaddress: {% /sbin/ifconfig eth0 | awk -F ' *|:' '/inet addr/{print $4}' %}

Is there a way to achieve this? I know this can be achived using shell and register module. But that is not what I am looking at since I need to add certain conditions before setting the variable value.

1 Answer 1

1

You could use hostvars facts like this:

{{ hostvars[host]['ansible_eth1']['ipv4']['address'] }}

Make sure that you set:

- hosts: whatever
  gather_facts: yes

See: http://docs.ansible.com/ansible/playbooks_variables.html#information-discovered-from-systems-facts

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.