# recommended way to statically configure network interfaces on centos-7 with ansible?

**URL:** <https://forum.ansible.com/t/recommended-way-to-statically-configure-network-interfaces-on-centos-7-with-ansible/17495>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [February 10, 2015, 9:34pm UTC](https://forum.ansible.com/t/recommended-way-to-statically-configure-network-interfaces-on-centos-7-with-ansible/17495 "2015-02-10T21:34:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cohen.ben](https://avatars.discourse-cdn.com/v4/letter/c/c89c15/32.png) [@cohen.ben](https://forum.ansible.com/u/cohen.ben)\
**Post date:** [February 10, 2015, 9:34pm UTC](https://forum.ansible.com/t/recommended-way-to-statically-configure-network-interfaces-on-centos-7-with-ansible/17495/1 "2015-02-10T21:34:12Z")

</div>

I’m new to ansible and a little googling hasn’t lead me quickly towards the right solution to my question.

What’s the ‘with the grain’ way to assign static network settings to a centos-7 host with ansible. I feel like this must be a pretty common need – and there must be a lot of people with questions about the right approach to take after all the changes to the network configuration system that comes with transitioning from rhel-6 to rhel-7 (namely: network-manager by default, consistent device naming from the kernel by default, systemd).

Prior to ansible I had been uninstalling network-manager and manually configuring hosts via /etc/init.d/network-scripts/ifcfg-\* files – I think I could do the same thing – generating the correct ifcfg-\* file using the ansible\_default\_ipv4[‘interface’] fact …?

```auto
    "ansible_default_ipv4": {
        "address": <snip>,
        "alias": "enp3s0",
        "gateway": <snip>,
        "interface": "enp3s0",
        "macaddress": <snip>,
        "mtu": 1500,
        "netmask": "255.255.255.128",
        "network": <snip>,
        "type": "ether"
    }

```

Ansible far is so great and for this I want to make sure I’m not going unnecessarily against the ansible grain. I’m willing to not uninstall network-manager if there are good ways to manage the network-manager mediated interface configuration through ansible …

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [February 11, 2015, 10:04am UTC](https://forum.ansible.com/t/recommended-way-to-statically-configure-network-interfaces-on-centos-7-with-ansible/17495/2 "2015-02-11T10:04:55Z")

</div>

Hi Ben,

Yes, I believe that would be an acceptable solution since I don't see  
any module for that specifically yet.

You could use the template module to deploy the ifcfg-\* files based on  
the variables, as you suggested.

[http://docs.ansible.com/template\_module.html](http://docs.ansible.com/template_module.html)  
[http://docs.ansible.com/service\_module.html](http://docs.ansible.com/service_module.html)

Regards,  
Giovanni
