# Create file depending on the network

**URL:** <https://forum.ansible.com/t/create-file-depending-on-the-network/32009>\
**Category:** Ansible Project\
**Created:** [January 20, 2020, 6:33pm UTC](https://forum.ansible.com/t/create-file-depending-on-the-network/32009 "2020-01-20T18:33:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xxmlud\_gnu](https://avatars.discourse-cdn.com/v4/letter/x/d07c76/32.png) [@xxmlud\_gnu](https://forum.ansible.com/u/xxmlud_gnu)\
**Post date:** [January 20, 2020, 6:33pm UTC](https://forum.ansible.com/t/create-file-depending-on-the-network/32009/1 "2020-01-20T18:33:21Z")

</div>

Hi!,

I need help. I want to deploy some file with some modifications. The deployment policy is that depending on the network the server belongs to, it will deploy some files or others.

I can’t compare the “ansible\_facts” with “vars”

##### CONFIGURATION

Example playbook:

```auto
---
- name: Create file
hosts: server
gather_facts: true
vars:
vlan:
- netname: 192.168.3.0
netface: "{{ ansible_interfaces }}"

```

Tasks:

```auto
tasks:
- name:
file:
path: /tmp/filetest
state: touch
when:
(hostvars[inventory_hostname]['ansible_%s' % item.0.netface]|default({}))
.get('ipv4', {}).get('network') == item.0.netname
loop:
- "{{ vlan }}"

```

Result:

```auto
ok: [server] => {
"ansible_default_ipv4.network": "192.168.3.0"
}

skipping: [server] => (item=[{u'netface': [u'lo', u'eth3', u'eth2', u'eth1', u'eth0'], u'netname': u'192.168.3.0'}]) => {
"ansible_loop_var": "item",
"changed": false,
"item": [
{
"netface": [
"lo",
"eth3",
"eth2",
"eth1",
"eth0"
],
"netname": "192.168.3.0"
}
],
"skip_reason": "Conditional result was False"
}

```

##### OS / ENVIRONMENT

Centos 7.7

##### ADDITIONAL INFORMATION

What happens is that the “when” condition is not working. And my server does have a network card on 192.168.3.0.

Thanks!,  
BR
