network: ansible-lint fixes

This commit is contained in:
Timo Makinen 2022-10-30 15:20:03 +00:00
parent d833b57877
commit 4b0f5522c8
4 changed files with 79 additions and 61 deletions

View file

@ -1,14 +1,18 @@
--- ---
- block: - name: Restart network
- name: restart network ansible.builtin.command:
command: /bin/sh /etc/netstart argv:
when: ansible_os_family == "OpenBSD" - /bin/sh
- /etc/netstart
- name: Reload network manager connections
ansible.builtin.command:
argv:
- nmcli
- c
- reload
- block: - name: Restart keepalived
- name: reload network manager connections ansible.builtin.service:
command: nmcli c reload name: keepalived
- name: restart keepalived state: restarted
service:
name: keepalived
state: restarted
when: ansible_os_family == "RedHat"

View file

@ -1,39 +1,41 @@
--- ---
- name: Create ethernet interface configurations
- name: create ethernet interface configurations ansible.builtin.template:
template:
src: hostname.if.j2 src: hostname.if.j2
dest: "/etc/hostname.{{ item.device }}" dest: "/etc/hostname.{{ item.device }}"
mode: 0600 mode: 0600
owner: root owner: root
group: "{{ ansible_wheel }}" group: "{{ ansible_wheel }}"
with_items: "{{ network_interfaces }}" with_items: "{{ network_interfaces }}"
notify: restart network notify: Restart network
- block: - name: Create carp interface configurations
- name: create carp interface configurations ansible.builtin.template:
template: src: hostname.carp.j2
src: hostname.carp.j2 dest: "/etc/hostname.carp{{ item.vhid }}"
dest: "/etc/hostname.carp{{ item.vhid }}" mode: 0600
mode: 0600 owner: root
owner: root group: "{{ ansible_wheel }}"
group: "{{ ansible_wheel }}" with_items: "{{ network_vip_interfaces }}"
with_items: "{{ network_vip_interfaces }}" notify: Restart network
notify: restart network
- name: enable carp preempt
sysctl:
name: net.inet.carp.preempt
value: "1"
when: when:
- network_vip_interfaces is defined - network_vip_interfaces is defined
- network_vip_interfaces != [] - network_vip_interfaces != []
- name: set default gateway - name: Enable CARP preempt
copy: ansible.posix.sysctl:
name: net.inet.carp.preempt
value: "1"
when:
- network_vip_interfaces is defined
- network_vip_interfaces != []
- name: Set default gateway
ansible.buitin.copy:
content: "{{ network_default_gateway }}\n" content: "{{ network_default_gateway }}\n"
dest: /etc/mygate dest: /etc/mygate
mode: 0600 mode: 0600
owner: root owner: root
group: "{{ ansible_wheel }}" group: "{{ ansible_wheel }}"
notify: restart network notify: Restart network
when: network_default_gateway is defined when: network_default_gateway is defined

View file

@ -1,39 +1,51 @@
--- ---
- name: get interface uuid - name: Get interface uuid
command: ansible.builtin.command:
cmd: nmcli -f "DEVICE,UUID,NAME" c show argv:
- nmcli
- -f
- DEVICE,UUID,NAME
- c
- show
changed_when: false changed_when: false
check_mode: false check_mode: false
register: interface_uuid register: interface_uuid
- name: create ethernet interface configurations - name: Create ethernet interface configurations
template: ansible.builtin.template:
src: ifcfg-eth.j2 src: ifcfg-eth.j2
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.device }}" dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.device }}"
mode: 0644 mode: 0644
owner: root owner: root
group: "{{ ansible_wheel }}" group: "{{ ansible_wheel }}"
notify: reload network manager connections notify: Reload network manager connections
with_items: "{{ network_interfaces }}" with_items: "{{ network_interfaces }}"
- block: - name: Install keepalived
- name: install keepalived ansible.builtin.package:
package: name: keepalived
name: keepalived state: installed
state: installed when:
- name: create keepalived config - network_vip_interfaces is defined
template: - network_vip_interfaces != []
dest: /etc/keepalived/keepalived.conf
src: keepalived.conf.j2 - name: Create keepalived config
mode: 0600 ansible.builtin.template:
owner: root dest: /etc/keepalived/keepalived.conf
group: "{{ ansible_wheel }}" src: keepalived.conf.j2
notify: restart keepalived mode: 0600
- name: enable keepalived owner: root
service: group: "{{ ansible_wheel }}"
name: keepalived notify: Restart keepalived
state: started when:
enabled: true - network_vip_interfaces is defined
- network_vip_interfaces != []
- name: Enable keepalived
ansible.builtin.service:
name: keepalived
state: started
enabled: true
when: when:
- network_vip_interfaces is defined - network_vip_interfaces is defined
- network_vip_interfaces != [] - network_vip_interfaces != []

View file

@ -1,9 +1,9 @@
--- ---
- name: include os spcific tasks - name: Include OS spcific tasks
include_tasks: "{{ ansible_os_family }}.yml" ansible.builtin.include_tasks: "{{ ansible_os_family }}.yml"
- name: create resolv.conf - name: Create resolv.conf
template: ansible.builtin.template:
src: resolv.conf.j2 src: resolv.conf.j2
dest: /etc/resolv.conf dest: /etc/resolv.conf
mode: 0644 mode: 0644