推荐使用静态设置来configuration一个centos-7networking接口

我是新手,一点点search引擎没有让我很快find正确的解决scheme,我的问题。

什么是“谷物”方式分配静态networking设置到一个centos-7主机与合理。 我觉得这一定是一个相当普遍的需求 – 在从rhel-6到rhel-7的过渡期间,在networkingconfiguration系统发生所有变化之后,必须有很多人提出正确的方法。 ,默认情况下为networkingpipe理器,默认情况下从内核systemd保持一致的设备命名)。

之前,我已经卸载networkingpipe理器,并通过/etc/init.d/network-scripts/ifcfg-*文件手动configuration主机 – 我想我可以做同样的事情ansible_default_ipv4事实:

"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远远如此伟大,为此我想确保我不会不必要地反对这个可靠的谷物。 我愿意不卸载networkingpipe理器,如果有很好的方法来pipe理networkingpipe理器介导的接口configuration通过ansible …

我回到这个后,变得更熟悉一个理智 – 我以为我会分享我的解决scheme。

首先要注意的是:NetworkManager具有configuration插件的概念 – 用于将外部信息源适配到NetworkManagerconfiguration中。 Redhat发布了一个名为ifcfg-rh的插件,它试图将/ etc / sysconfig / network-scripts / ifcfg *风格的configuration文件调整到NetworkManagerconfiguration中,但是这种方法存在一些问题……而network-scripts / ifcfg *configuration格式从来没有特别直接的…它也很混乱的networking脚本文件的变化的语义是什么 – 以及什么时候将完全采用新的设置。 此外,ifcfg- *types文件不支持NetworkManager支持的所有networkingconfiguration。

我发现放弃ifcfg-rh插件并使用keyfile插件取而代之变得更容易也更直接。

在任务/ main.yml中:

 --- - name: ensure NetworkManager is configured to use keyfile plugin copy: src=NetworkManager.conf dest=/etc/NetworkManager/NetworkManager.conf mode=0600 notify: - restart NetworkManager - wait for new network settings - name: ensure NetworkManager settings are initialized from appropriate keyfile configuration copy: src={{ myorg_network_profile }}.conf dest=/etc/NetworkManager/system-connections/ansible_generated.conf mode=0600 notify: - restart NetworkManager - reload network interface - wait for new network settings 

处理程序看起来像这样:


  - name: reload network interface shell: nmcli con reload - name: restart NetworkManager service: name=NetworkManager state=restarted - name: wait for new network settings sudo: false local_action: module: wait_for host={{ ansible_ssh_host | default(inventory_hostname) }} port=22 delay=10 timeout=300 

一个NetworkManager.conf如下所示:

 [main] plugin=keyfile 

然后我创build适合我要部署的各种networkingconfiguration的密钥文件configuration文件:

例如:files / dhcp.conf

 [connection] id=dhcp uuid=50263651-4f14-46bc-8dd8-818bf0fe3367 type=ethernet autoconnect=true [ipv6] method=auto [ipv4] method=auto 

或者对于具有静态networking设置的主机和两个子网上的IP:

 [connection] id=custom-connection-profile uuid=50263651-4f14-46bc-8dd8-818bf0fe3362 type=ethernet autoconnect=true [ipv6] method=auto [ipv4] method=manual dns=192.168.0.1;192.168.0.x; dns-search=foo.com; address1=192.168.0.4/24,192.168.0.1 address2=172.19.0.12/25,172.19.12.1 

要将随机ip中新安装的系统转换为具有静态分配地址的主机:

 ansible-playbook site.yml -i hosts.ini --extra_vars "ansible_ssh_host=<ip_address_of_newly_installed_host>" --limit <ansible_hostname_from_inventory> 

我认为这是一个很好的方法,但任何反馈都很高兴。