项目作者: mvrahden

项目描述 :
An Ansible role to define static IP, set hostname and setup iptables on debian-based systems.
高级语言:
项目地址: git://github.com/mvrahden/ansible-role-networking-setup.git
创建时间: 2019-07-15T14:18:44Z
项目社区:https://github.com/mvrahden/ansible-role-networking-setup

开源协议:MIT License

下载


ansible-role-networking-setup

An Ansible role to define static IPs, set hostnames and setup iptables on debian-based systems.

Table of Contents

Side notes

This package provides 3 “subtask” functionalities.
Each functionality can be addressed by adding it to the subtasks-list (e.g. subtasks: [ 'interfaces' ]).
The functionality values are as follows:

  • 'interfaces' - sets the network interface definitions based on given interface profiles, hence e.g. static IPs, dns-server, routing etc.
  • 'hostname' - sets the hostname, and statically cross-references all other hosts from the networking_group_name via the /etc/hosts-file
  • 'netfilter' - sets iptables definitions

The role performs a reboot of the hosts after all (sub)tasks of the role have been performed successfully.
This helps in updating the network environment of the host.
To avoid or bypass this reboot behavior, set the perform_reboot flag to false.

Role Variables

defaults/main.yml

Networking Interface Profiles

This is a list of interface profile definitions, which will be translated into the requirements of the default renderer for network configuration of each operating system, such as:

  • dhcpcd
  • NetworkManager
  • Netplan

This is the structure of the profile definitions:

  1. # profiles
  2. networking_interface_profiles:
  3. - type: iface
  4. interface: lo
  5. address_family: inet # or inet6 or ipx
  6. address_method: loopback # or dhcp
  7. auto: lo # optional; manpage interfaces(5)
  8. - type: iface
  9. interface: eth0
  10. address_family: inet # or inet6 or ipx
  11. address_method: static # or dhcp
  12. auto: eth0
  13. allow_hotplug: eth0
  14. cidr_notation: 192.168.1.150/24 # static ip as CIDR
  15. address: 192.168.1.150 # static ip
  16. netmask: 255.255.255.0 # results into CIDR suffix /24
  17. gateway: 192.168.1.1
  18. network: 192.168.1.0
  19. broadcast: 192.168.1.255
  20. dns_nameservers: # are there any local DNS Name Servers?
  21. - 192.168.1.100
  22. - 192.168.1.1
  23. - 8.8.8.8

iptable definitions

  1. networking_iptables_definitions:
  2. - chain: FORWARD
  3. ctstate: RELATED,ESTABLISHED
  4. in_interface: wlan0
  5. jump: ACCEPT
  6. out_interface: eth0
  7. state: present
  8. table: filter
  9. - chain: FORWARD
  10. in_interface: eth0
  11. jump: ACCEPT
  12. out_interface: wlan0
  13. state: present
  14. table: filter
  15. - chain: POSTROUTING
  16. jump: MASQUERADE
  17. out_interface: wlan0
  18. source: 192.168.1.0/24
  19. state: present
  20. table: nat

Sample Roles

Assuming you have the variable networking_interface_profiles defined.

Network interfaces and Static IPs

Setup static IPs as follows:

Attention: This Subtasks ends with a Reboot!

  1. roles:
  2. - role: mvrahden.networking-setup
  3. subtasks: [ 'interfaces' ]
  4. networking_interface_profiles: "{{ my_awesome_interface_profiles }}"

Hostname

Setup hostnames as follows:

  1. roles:
  2. - role: mvrahden.networking-setup
  3. subtasks: [ 'hostname' ]
  4. networking_group_name: my_clustered_hosts # inventory name
  5. networking_group_domain: example.com
  6. networking_device_interfaces: "{{ my_awesome_interface_profiles }}"

Dependencies

None

Requirements

Packages installed on your system:

License

MIT

Author Information

  • Menno van Rahden