Skip to content

Commit

Permalink
Correct mac generation block
Browse files Browse the repository at this point in the history
The block/rescue we were using in the mac generation task did not work
as expected. Because we use an iterator on the task and we can't iterate
over the entire block the task would fail when mac address lookups
within a running container didn't already exist but needed to be
created. This resulted in the task failing for a single host and being
removed from the inventory instead of running a rescue for only the
missing network.

The use of block/rescue has been removed. If the feature to loop over a
block is ever implemented [0] we can revisit how this action is done.

[0] - ansible/ansible#13262
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>

Change-Id: Ie4bc3b130874047a5cbd36b98ed86a731ae5c317
  • Loading branch information
cloudnull committed Nov 2, 2017
1 parent 82c1dfa commit c51afbe
Showing 1 changed file with 31 additions and 40 deletions.
71 changes: 31 additions & 40 deletions tasks/lxc_container_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,46 +48,37 @@
notify:
- Lxc container restart

- name: Network mac address block
block:
# NOTE(cloudnull): Should a container already be up and running with a defined container interface
# the shell command will use the MAC address already set within the container as
# it's value. This allows the tasks to remain idempotent while ensuring that a
# container restart isn't required to set a static mac.
- name: Set define static mac address from an existing interface
shell: |
C_PID="$(lxc-info --name {{ inventory_hostname }} --pid | awk '/PID:/ {print $2}')"
C_ADDR="/proc/${C_PID}/root/sys/class/net/{{ item.value.interface }}/address"
cat ${C_ADDR} > /var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}.hwaddr
args:
executable: /bin/bash
creates: "/var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}.hwaddr"
with_dict: "{{ container_networks | default({}) }}"
delegate_to: "{{ physical_host }}"
tags:
- skip_ansible_lint
rescue:
# NOTE(cloudnull): This task is being done to allow a container to have a static mac address.
# before this task a container had a dynamic mac address which would
# change when a container was restarted. This restart process causes terrible
# issues in several network intensive systems (RabbitMQ, Neutron, etc). To
# resolve the rotating mac address issue this task is setting the mac in a hwaddr
# file and a lookup is being used in the container-interface.ini template to render
# the static hardware address as expected.
- name: Set unique interface mac address (when no facts exist)
shell: |
echo "00:16:3e$(
for i in {1..6}; do
echo -n ${0123456789abcdef:$(( $RANDOM % 16 )):1}
done | sed -e 's/\(..\)/:\1/g'
)" > /var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}.hwaddr
args:
executable: /bin/bash
creates: "/var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}.hwaddr"
with_dict: "{{ container_networks | default({}) }}"
delegate_to: "{{ physical_host }}"
tags:
- skip_ansible_lint
# NOTE(cloudnull): Should a container already be up and running with a defined container interface
# the shell command will use the MAC address already set within the container as
# it's value. This allows the tasks to remain idempotent while ensuring that a
# container restart isn't required to set a static mac.
# This task is being done to allow a container to have a static mac address.
# before this task a container had a dynamic mac address which would
# change when a container was restarted. This restart process causes terrible
# issues in several network intensive systems (RabbitMQ, Neutron, etc). To
# resolve the rotating mac address issue this task is setting the mac in a hwaddr
# file and a lookup is being used in the container-interface.ini template to render
# the static hardware address as expected.
- name: Set define static mac address from an existing interface
shell: |
C_PID="$(lxc-info --name {{ inventory_hostname }} --pid | awk '/PID:/ {print $2}')"
C_ADDR="/proc/${C_PID}/root/sys/class/net/{{ item.value.interface }}/address"
HARDWARE_ADDR="/var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}.hwaddr"
HEXCHARS="0123456789abcdef"
if ! cat "${C_ADDR}" > "${HARDWARE_ADDR}"; then
echo "00:16:3e$(
for i in {1..6}; do
echo -n "${HEXCHARS:$(( $RANDOM % 16 )):1}"
done | sed -e 's/\(..\)/:\1/g'
)" > "${HARDWARE_ADDR}"
fi
args:
executable: /bin/bash
creates: "/var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}.hwaddr"
with_dict: "{{ container_networks | default({}) }}"
delegate_to: "{{ physical_host }}"
tags:
- skip_ansible_lint
when:
- lxc_container_fixed_mac | bool

Expand Down

0 comments on commit c51afbe

Please sign in to comment.