# How do you parameterize ansible\_eth\* facts and use it?

**URL:** <https://forum.ansible.com/t/how-do-you-parameterize-ansible-eth-facts-and-use-it/18341>\
**Category:** Ansible Project\
**Created:** [May 29, 2015, 4:42am UTC](https://forum.ansible.com/t/how-do-you-parameterize-ansible-eth-facts-and-use-it/18341 "2015-05-29T04:42:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![t\_goto](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@t\_goto](https://forum.ansible.com/u/t_goto)\
**Post date:** [May 29, 2015, 4:42am UTC](https://forum.ansible.com/t/how-do-you-parameterize-ansible-eth-facts-and-use-it/18341/1 "2015-05-29T04:42:18Z")

</div>

Hello, ansible experts.

I’m trying to parameterize eth interface in `group_vars/all` so that I can use it in playbook easier.

group\_vars/all file looks like this.

`my_int_if: eth1 my_int_ip: "{{ ansible_eth1.ipv4.address }}" my_int_obj: "{{ ansible_eth1 }}"`

I could successfuly use those variables with following playbook and template file.

`

- name: copy mysql file  
tempalte: src=galera.cnf.j2 dest=/etc/my.cnf.d/galera.cnf  
`

`  
bind-address={{ my\_int\_ip }}

# becomes this as intended.

bind-address=192.168.50.126  
`

But now, when I tried to use “{{my\_int\_ip}}” from playbook directly, It didin’t work as intended.

`

- name: galera cluster replication bluh  
mysql\_user:  
name: wsrep\_sst-user  
host: “{{ hostvars[item].my\_int\_ip }}”  
password: password  
priv: “_._:ALL”  
with\_items: play\_hosts  
`

According to the Error message, it looked like this variable was not expanded well.

`msg: (1396, "Operation CREATE USER failed for 'wsrep_sst-user'@'{# ansible_eth1.ipv4.address #}'")`

I would like to know why I could use it at template, and not at playbook.

And if you have any good advice to parameterize the ethernet for firewall, bind address, and etc., please show me!!

Thank you!

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [May 29, 2015, 6:03am UTC](https://forum.ansible.com/t/how-do-you-parameterize-ansible-eth-facts-and-use-it/18341/2 "2015-05-29T06:03:53Z")

</div>

if i understand correctly, you are setting my\_int\_if: eth1 and then setting my\_int\_ip: “{{ ansible\_eth1.ipv4.address }}” which is always hardcoded to eth1.

i think what you would want is  
in group\_vars/all

my\_int\_if: eth1

and reference it in template and other places via:

bind-address={{ hostvars[inventory\_hostname][‘ansible\_’ + my\_int].ipv4.address }}

and in playbook as

host={{ hostvars[item][‘ansible\_’ + my\_int].ipv4.address }}

---

<div class="post-metadata">

**Author:** ![t\_goto](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@t\_goto](https://forum.ansible.com/u/t_goto)\
**Post date:** [May 29, 2015, 6:45am UTC](https://forum.ansible.com/t/how-do-you-parameterize-ansible-eth-facts-and-use-it/18341/3 "2015-05-29T06:45:16Z")

</div>

Hello, benno joy.

Thanks for understanding my poor English.  
Basic concept of my\_int\_\* is to parameterize ethernet interface in template and playbook,  
so that changing group\_vars/all can accommodate different OS/machines such as eth1, p3p4, etc.

I tried your code, but still same error message ☹

2015年5月29日金曜日 15時03分57秒 UTC+9 benno joy:

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [May 29, 2015, 6:49am UTC](https://forum.ansible.com/t/how-do-you-parameterize-ansible-eth-facts-and-use-it/18341/4 "2015-05-29T06:49:58Z")

</div>

Sorry i had a typo:

if the variable is “my\_int\_if: eth0”

then in playbook it woudl be referenced as

host={{ hostvars[item][‘ansible\_’ + my\_int\_if].ipv4.address }}

earlier i had only put “my\_int”

if still it doesnt work, can you please paste your group\_vars and plybook in gist and let us know the version of ansible you are using.

- Benno

---

<div class="post-metadata">

**Author:** ![t\_goto](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@t\_goto](https://forum.ansible.com/u/t_goto)\
**Post date:** [May 29, 2015, 7:32am UTC](https://forum.ansible.com/t/how-do-you-parameterize-ansible-eth-facts-and-use-it/18341/5 "2015-05-29T07:32:47Z")

</div>

Your code perfectly worked for me.

ThankYOU!! Mr.benno.

The reason it couldn’t get through at first was because of mysql FLUSH PRIVILEGES.  
[http://stackoverflow.com/questions/5555328/error-1396-hy000-operation-create-user-failed-for-jacklocalhost](http://stackoverflow.com/questions/5555328/error-1396-hy000-operation-create-user-failed-for-jacklocalhost)

After FLUSH PRIVILEGES in mysql console , everything worked fine with your code 🙂

Here’s practice code I used.  
[https://gist.github.com/tomgoto/2535d87c4157938ea534](https://gist.github.com/tomgoto/2535d87c4157938ea534)

Thank you again! 🙂
