- 红帽官方推荐使用network-roles
- nmcli模块
- hostname模块
创建group_vars/webservers/目录
目录下创建network.yml文件
---
network-connections:
- name: enp2s0
type: ethernet
ip:
address:
- 172.25.250.30/24
创建play.yml文件
---
- name: 网络管理示例
hosts: webservers
roles:
- rhel-system-roles.network
执行play.yml即可
ansible-playbook play.yml
nmcli模块
| 参数 | 解释 |
|---|---|
| conn_name | |
| autoconnect | |
| dns4 | dns地址 |
| gw4 | 网关 |
| ifname | 网卡 |
| ip4 | ipv4地址 |
| state | 启用或者禁用 |
| type | 网络类型 |
示例代码:
- name: NIC配置 nmcli: conn_name: ens4-conn ifname: ens4 type: ethernet ipv: 172.25.250.30/24 gw4: 172.25.25-.1 state: present
hostname模块
配置主机名
- name: 配置主机名 hostname: name: managedhost1



