我对ansible还不熟悉,稍微谷歌一下也不能让我很快找到正确的解决方案。
什么是‘与谷物’的方式,以分配静态网络设置的centos-7主机与ansible。我觉得这一定是一个非常普遍的需求--必须有很多人质疑在从HEHL-6到HIL-7(即默认的网络管理器,默认情况下从内核命名,systemd)对网络配置系统的所有更改之后,应该采取什么正确的方法。
在ansible之前,我一直在卸载网络管理器,并通过/etc/init.d/network/ifcfg-*文件手动配置主机--我认为我可以使用ansible_default_ipv4事实对ansible做同样的事情:
"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 .
发布于 2015-03-03 23:02:47
当我对ansible变得更加熟悉后,我又回到了这个话题--我想分享我的解决方案。
首先要注意的是: NetworkManager有配置插件的概念--用于将外部信息源调整到NetworkManager配置中。Redhat分发一个名为ifcfg的插件,它试图将/etc/sysconfig/network/ifcfg*样式的配置文件调整到NetworkManager配置中,但是这种方法有很多缺点.网络脚本/ifcfg*配置格式从来都不是很简单.对于网络更改的语义--脚本文件--以及新设置将在什么时候应用,这也是相当令人困惑的。此外,ifcfg-*类型文件不支持NetworkManager支持的所有网络配置。
我发现放弃ifcfg插件,转而使用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然后,我创建了适合于我想要部署的各种网络配置的keyfile配置文件:
示例:file/dhcp.conf
[connection]
id=dhcp
uuid=50263651-4f14-46bc-8dd8-818bf0fe3367
type=ethernet
autoconnect=true
[ipv6]
method=auto
[ipv4]
method=auto或者对于具有静态网络设置和两个子网上的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>我认为这是一个很好的方法,但对任何虚弱的人都很高兴。
发布于 2019-12-02 14:53:53
现在(2019年秋季),原生的不可用nmcli模块将是答案:https://docs.ansible.com/ansible/latest/modules/nmcli_module.html
https://serverfault.com/questions/666579
复制相似问题