From 10dae58b0a006d4e94a1698cdba0958fa5927966 Mon Sep 17 00:00:00 2001 From: Piotr Gbyliczek Date: Fri, 13 May 2016 13:17:57 +0100 Subject: [PATCH 1/2] initial commit of fork --- .gitignore | 1 + LICENSE | 165 +++++++++++++++++++++++++++++++++++ README.md | 89 +++++++++++++++++++ defaults/main.yml | 47 ++++++++++ handlers/main.yml | 5 ++ meta/.galaxy_install_info | 1 + meta/main.yml | 41 +++++++++ tasks/el.yml | 50 +++++++++++ tasks/main.yml | 8 ++ templates/el_ifcfg-bond.j2 | 24 +++++ templates/el_ifcfg-slaves.j2 | 17 ++++ tests/inventory | 1 + tests/test.yml | 5 ++ 13 files changed, 454 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/.galaxy_install_info create mode 100644 meta/main.yml create mode 100644 tasks/el.yml create mode 100644 tasks/main.yml create mode 100644 templates/el_ifcfg-bond.j2 create mode 100644 templates/el_ifcfg-slaves.j2 create mode 100644 tests/inventory create mode 100644 tests/test.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f7d541 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vars/main.yml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..65c5ca8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ba88c55 --- /dev/null +++ b/README.md @@ -0,0 +1,89 @@ +bonding +========= + +Role to create / configure properly bonding interfaces + +Requirements +------------ + +Ansible 2.0, python-netaddr + +Role Variables +-------------- + +| Name | Type | Required | Default | Description +|--- |--- |--- |--- |--- +| slaves | list | yes | None | List of the slaves part of the bond +| bond | string | yes | None | Name of the bond interface +| apply | boolean | no | false | Set to true to write the real configuration files in sysconfig +| apply_now | boolean | no | false | Restart the network restart after writing the configuration files +| el_network_sysconfig | string | no | /etc/sysconfig/network-scripts | Default directory for RH/CentOS +| tmp_dir | string | no | /tmp | TMP directory for the configuration files +| bond_options | list of dict | no | [{ 'key': 'mode', 'value': 'lacp'}, { 'key': 'miimon', 'value': '80'}] | Some default values for Bonding Options +| mtu | int | no | 1500 | Value of the MTU for the interface +| enable_ipv4 | boolean | no | false | Determines if you want to use ipv4 settings for the bond interface +| manage_gateway | boolean | no | false | Determines if you want to configure the gateway on the bond +| manage_dns_servers | boolean | no | false | Determines if you want to configure DNS on the bond configuration +| manage_hw_addr | boolean | no | true | Determines if you want to write the HWADDR in the slaves configuration +| ip_addr | string | no | None | The IPv4 for the bond interface +| netmask | string | no | None | The Netmask for the bond interface +| gateway | string | no | None | The gateway to use for the bond interface +| dns1 | string | no | None | DNS1 server +| dns2 | string | no | None | DNS2 server +| enable_ipv6 | boolean | no | true | Enable IPv6 on the bond interface +| init_ipv6 | boolean | no | true | Enable IPv6 initiatialization +| ipv6_autoconf | boolean | no | no | Enable IPv6 autoconfiguration +| keep_slave_ipv4 | boolean | no | false | Determines if you want to keep the slaves existing IPv4 configuration + + +Dependencies +------------ + +None + +Example Playbook +---------------- + +``` + +- hosts: nc-9 + roles: + - bonding + vars: + - slaves: + - eth0 + - eth1 + - bond: bond0 + +``` + +``` + +- hosts: nc-9 + roles: + - bonding + vars: + - slaves: + - eth0 + - eth1 + - bond: bond0 + - bond_options: + - { 'key': 'mode', 'value': '4'} + - { 'key': 'miimon', 'value': '100'} + - { 'key': 'xmit_hash_policy', 'value': 'layer2+3'} + - { 'key': 'lacp_rate', 'value': 'fast'} + - { 'key': 'ad_select', 'value': 'bandwidth'} + + +``` + + +License +------- + +GPLv3 + +Author Information +------------------ + +John Preston [John Mille] diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..7990af4 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,47 @@ +--- +# defaults file for bonding + +# Set to true to apply to sysconfig files +apply: false + +# Set to true to restart network service after files creation +apply_now: false + +el_network_sysconfig: /etc/sysconfig/network-scripts +tmp_dir: /tmp + + +# Bonding options +# More information on https://www.kernel.org/doc/Documentation/networking/bonding.txt + +bond_options: +- { 'key': 'mode', 'value': 'lacp'} +- { 'key': 'miimon', 'value': '80'} +- { 'key': 'xmit_hash_policy', 'value': '2'} + +#- { 'key': '', 'value': ''} + +# Normal values +mtu: 1500 + +# Bonding IP settings + +enable_ipv4: false +manage_gateway: false +manage_dns_servers: false +manage_hw_addr: true +ip_addr: +netmask: +gateway: +dns1: +dns2: + +# IPv6 options + +enable_ipv6: true +init_ipv6: yes +ipv6_autoconf: no + +# Slaves options + +keep_slave_ipv4: false diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..32ebaf0 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +--- +# handlers file for bonding + +- name: restart network + service: name=network state=restarted diff --git a/meta/.galaxy_install_info b/meta/.galaxy_install_info new file mode 100644 index 0000000..83333ad --- /dev/null +++ b/meta/.galaxy_install_info @@ -0,0 +1 @@ +{install_date: 'Thu May 12 08:46:44 2016', version: master} diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..5969f0c --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,41 @@ +galaxy_info: + author: John Preston [JMille] + description: Bond configuration files creator + company: + license: GPLv3 + min_ansible_version: 1.9 + + github_branch: master + platforms: + - name: EL + versions: + - 6 + - 7 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + # - wily + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + galaxy_tags: + - networking + - bonding + +dependencies: [] diff --git a/tasks/el.yml b/tasks/el.yml new file mode 100644 index 0000000..ca646c5 --- /dev/null +++ b/tasks/el.yml @@ -0,0 +1,50 @@ +--- +# tasks file for bonding + +- name: Create the slave interfaces configuration files + template: src=el_ifcfg-slaves.j2 dest="{{ el_network_sysconfig }}/ifcfg-{{ item }}" backup=yes + with_items: + - "{{ slaves }}" + when: + - apply + tags: + - el + - bond + +- name: Create the bonding iface + template: src=el_ifcfg-bond.j2 dest="{{ el_network_sysconfig }}/ifcfg-{{ item }}" + with_items: + - "{{ bond }}" + when: + - apply + - ("{{ slaves| length }}" >=2) + notify: restart network + tags: + - el + - bond + +- name: Apply settings NOW + service: name=network state=restarted + when: + - apply_now + +- name: Create the slave interfaces configuration files + template: src=el_ifcfg-slaves.j2 dest="{{ tmp_dir }}/ifcfg-{{ item }}" + with_items: + - "{{ slaves }}" + when: + - not apply + tags: + - el + - bond + +- name: Create the bonding iface + template: src=el_ifcfg-bond.j2 dest="{{ tmp_dir }}/ifcfg-{{ item }}" + with_items: + - "{{ bond }}" + when: + - not apply + - ("{{ slaves|length }}" >=2) + tags: + - el + - bond diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..97e2f87 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,8 @@ +--- +# tasks file for bonding + +- name: Create configuration files + include: el.yml + when: (ansible_os_family == "CentOS") or + (ansible_os_family == "RedHat") + become: yes diff --git a/templates/el_ifcfg-bond.j2 b/templates/el_ifcfg-bond.j2 new file mode 100644 index 0000000..d15df0c --- /dev/null +++ b/templates/el_ifcfg-bond.j2 @@ -0,0 +1,24 @@ +{% set iface = 'ansible_' + item %} +NAME="{{ item }}" +DEVICE="{{ item }}" +BONDING_OPTS="{%for bond_option in bond_options %}{{ bond_option.key }}={{ bond_option.value}} {%endfor%}" +MTU="{{ mtu }}" +NOZEROCONF=yes + +{%if enable_ipv4 %} +{% if ip_addr and netmask %} +IPADDR="{{ ip_addr }}" +NETMASK="{{ netmask }}" +{% endif %} +{%if manage_gateway %} +GATEWAY="{{ gateway }}" +{% endif %} +{%if manage_dns_servers %} +DNS1="{{ dns1 }}" +DNS2="{{ dns2 }}" +{% endif %} +{% endif %} +{% if enable_ipv6 %} +IPV6INIT="{{ init_ipv6 }}" +IPV6_AUTOCONF="{{ ipv6_autoconf }}" +{% endif %} diff --git a/templates/el_ifcfg-slaves.j2 b/templates/el_ifcfg-slaves.j2 new file mode 100644 index 0000000..f380de4 --- /dev/null +++ b/templates/el_ifcfg-slaves.j2 @@ -0,0 +1,17 @@ +{% set iface = 'ansible_' + item %} +NAME="{{ item }}" +DEVICE="{{ item }}" +BOOTPROTO=none +ONBOOT=yes +SLAVE=yes +MASTER="{{ bond }}" +MTU="{{ mtu }}" +{% if manage_hw_addr %} +HWADDR="{{ hostvars[inventory_hostname][iface].macaddress }}" +{% endif %} +{% if keep_slave_ipv4 %} +{% if hostvars[inventory_hostname][iface].ipv4 %} +IPADDR="{{ hostvars[inventory_hostname][iface].ipv4.address }}" +NETMASK="{{ hostvars[inventory_hostname][iface].ipv4.netmask }}" +{% endif %} +{% endif %} diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..d18580b --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +localhost \ No newline at end of file diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..a31e13a --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - . \ No newline at end of file From 095e2fc862254c66d2104a271a7a8b294ca1b5ec Mon Sep 17 00:00:00 2001 From: Piotr Gbyliczek Date: Mon, 16 May 2016 10:54:27 +0100 Subject: [PATCH 2/2] added NetworkManager support --- defaults/main.yml | 3 +++ handlers/main.yml | 3 +++ tasks/el.yml | 33 +++++++++++++++++++++++++++++++++ templates/el_ifcfg-bond.j2 | 4 ++++ 4 files changed, 43 insertions(+) diff --git a/defaults/main.yml b/defaults/main.yml index 7990af4..b336079 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,9 @@ --- # defaults file for bonding +# Set to true if using NetworkManager +network_manager: false + # Set to true to apply to sysconfig files apply: false diff --git a/handlers/main.yml b/handlers/main.yml index 32ebaf0..c938211 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -3,3 +3,6 @@ - name: restart network service: name=network state=restarted + +- name: restart networkmanager + service: name=NetworkManager state=restarted diff --git a/tasks/el.yml b/tasks/el.yml index ca646c5..3155389 100644 --- a/tasks/el.yml +++ b/tasks/el.yml @@ -23,6 +23,39 @@ - el - bond + +- name: Create the slave interfaces configuration files + template: src=el_ifcfg-slaves.j2 dest="{{ el_network_sysconfig }}/ifcfg-{{ item }}" backup=yes + with_items: + - "{{ slaves }}" + when: + - apply + - network_manager + tags: + - el + - bond + - network_manager + +- name: Create the bonding iface + template: src=el_ifcfg-bond.j2 dest="{{ el_network_sysconfig }}/ifcfg-{{ item }}" + with_items: + - "{{ bond }}" + when: + - apply + - ("{{ slaves| length }}" >=2) + - network_manager + notify: restart NetworkManager + tags: + - el + - bond + - network_manager + +- name: Apply settings NOW + service: name=NetworkManager state=restarted + when: + - apply_now + - network_manager + - name: Apply settings NOW service: name=network state=restarted when: diff --git a/templates/el_ifcfg-bond.j2 b/templates/el_ifcfg-bond.j2 index d15df0c..22ac030 100644 --- a/templates/el_ifcfg-bond.j2 +++ b/templates/el_ifcfg-bond.j2 @@ -4,6 +4,10 @@ DEVICE="{{ item }}" BONDING_OPTS="{%for bond_option in bond_options %}{{ bond_option.key }}={{ bond_option.value}} {%endfor%}" MTU="{{ mtu }}" NOZEROCONF=yes +{%if network_manager %} +TYPE=bond +BONDING_MASTER=yes +{% endif %} {%if enable_ipv4 %} {% if ip_addr and netmask %}