56 lines
1.8 KiB
YAML
56 lines
1.8 KiB
YAML
---
|
|
# NOTE(mattymo): This can be removed after release of Calico 2.1
|
|
|
|
- name: Get timestamp from oldest dhclient pid
|
|
shell: "pgrep -o dhclient | xargs --no-run-if-empty -I{} stat --printf='%Y' /proc/{}"
|
|
register: oldest_dhclient_time
|
|
|
|
- name: check if /etc/dhclient.conf exists
|
|
stat:
|
|
path: /etc/dhclient.conf
|
|
register: dhclient_find_stat
|
|
|
|
- name: target dhclient conf file for /etc/dhclient.conf
|
|
set_fact:
|
|
dhclientconffile: /etc/dhclient.conf
|
|
when: dhclient_find_stat.stat.exists
|
|
|
|
- name: target dhclient conf file for /etc/dhcp/dhclient.conf
|
|
set_fact:
|
|
dhclientconffile: /etc/dhcp/dhclient.conf
|
|
when: not dhclient_find_stat.stat.exists
|
|
|
|
- name: Gather info on dhclient.conf
|
|
stat:
|
|
path: "{{ dhclientconffile }}"
|
|
register: dhclient_stat
|
|
|
|
- name: See if oldest dhclient process is older than dhclient.conf
|
|
set_fact:
|
|
needs_network_reset: "{{ oldest_dhclient_time.stdout != '' and oldest_dhclient_time.stdout|int < dhclient_stat.stat.mtime }}"
|
|
|
|
- name: update ansible time
|
|
setup: filter=ansible_date_time
|
|
|
|
- name: Calculate number of seconds since dhclient.conf was modified
|
|
set_fact:
|
|
mtime_dhclientconf: "{{ ansible_date_time.epoch|int - dhclient_stat.stat.mtime|int }}"
|
|
|
|
- name: Set networking service name
|
|
set_fact:
|
|
networking_service_name: >-
|
|
{% if ansible_os_family == "RedHat" -%}
|
|
network
|
|
{%- elif ansible_os_family == "Debian" -%}
|
|
networking
|
|
{%- endif %}
|
|
|
|
- name: Restart networking, dhclient, and calico-felix
|
|
shell: "{{ item }}"
|
|
when: needs_network_reset|bool and inventory_hostname in groups['k8s-cluster']
|
|
failed_when: false # in case dhclient was stopped
|
|
with_items:
|
|
- killall -q dhclient --older-than {{ mtime_dhclientconf }}s
|
|
- systemctl restart {{ networking_service_name }}
|
|
- docker exec calico-node killall -HUP calico-felix
|