From 13b6d692b01c3824cbea74c2bf1546ca0fa898af Mon Sep 17 00:00:00 2001 From: wuchunyang Date: Tue, 9 Mar 2021 15:21:48 +0800 Subject: [PATCH] Use User and Group variables instead of sudo use User and Group in octavia-interface service. this way looks more graceful this change also fix the octavia-interface does not restart when the octavia-interface.service changed. Change-Id: I9d253d7519b1774985d165a080047fdbecd321b4 --- ansible/roles/octavia/tasks/hm-interface.yml | 3 ++- .../roles/octavia/templates/octavia-interface.service.j2 | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ansible/roles/octavia/tasks/hm-interface.yml b/ansible/roles/octavia/tasks/hm-interface.yml index 2ce5170fa8..9cbc8f188f 100644 --- a/ansible/roles/octavia/tasks/hm-interface.yml +++ b/ansible/roles/octavia/tasks/hm-interface.yml @@ -67,11 +67,12 @@ dest: /etc/systemd/system/octavia-interface.service register: octavia_interface -- name: Reload octavia-interface.service if required +- name: Restart octavia-interface.service if required become: True systemd: name: octavia-interface daemon_reload: yes + state: restarted when: octavia_interface.changed - name: Enable and start octavia-interface.service diff --git a/ansible/roles/octavia/templates/octavia-interface.service.j2 b/ansible/roles/octavia/templates/octavia-interface.service.j2 index 8a38091838..7f04d9fb42 100644 --- a/ansible/roles/octavia/templates/octavia-interface.service.j2 +++ b/ansible/roles/octavia/templates/octavia-interface.service.j2 @@ -5,10 +5,12 @@ After=docker.service [Service] Type=oneshot +User=root +Group=root RemainAfterExit=true -ExecStartPre=/usr/bin/sudo /sbin/ip link set dev {{ octavia_network_interface }} address {{ port_info.port.mac_address }} -ExecStart=/usr/bin/sudo /sbin/dhclient -v {{ octavia_network_interface }} -cf /etc/dhcp/octavia-dhclient.conf -ExecStop=/usr/bin/sudo /sbin/dhclient -r {{ octavia_network_interface }} +ExecStartPre=/sbin/ip link set dev {{ octavia_network_interface }} address {{ port_info.port.mac_address }} +ExecStart=/sbin/dhclient -v {{ octavia_network_interface }} -cf /etc/dhcp/octavia-dhclient.conf +ExecStop=/sbin/dhclient -r {{ octavia_network_interface }} [Install] WantedBy=multi-user.target