From 184ac6a4e624531592e23bf452944d671cbcd8fd Mon Sep 17 00:00:00 2001 From: Matthew Mosesohn Date: Tue, 27 Aug 2019 20:16:42 +0300 Subject: [PATCH] Parse calico nodes as json (#5114) --- roles/network_plugin/calico/rr/tasks/main.yml | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/roles/network_plugin/calico/rr/tasks/main.yml b/roles/network_plugin/calico/rr/tasks/main.yml index 0c93a5506..5b80cf1ac 100644 --- a/roles/network_plugin/calico/rr/tasks/main.yml +++ b/roles/network_plugin/calico/rr/tasks/main.yml @@ -3,27 +3,24 @@ include_tasks: pre.yml - name: Calico-rr | Fetch current node object - command: "{{ bin_dir }}/calicoctl.sh get node {{ inventory_hostname }} -oyaml" + command: "{{ bin_dir }}/calicoctl.sh get node {{ inventory_hostname }} -ojson" register: calico_rr_node + until: calico_rr_node is succeeded + delay: "{{ retry_stagger | random + 3 }}" + retries: 10 -# FIXME(mattymo): Use jsonpatch when ansible/ansible#52931 is merged - name: Calico-rr | Set route reflector cluster ID - shell: >- - echo -e '{{ calico_rr_node.stdout }}' | - sed '/bgp:/a \ \ \ \ routeReflectorClusterID: {{ cluster_id }}' - register: calico_rr_node - when: '("routeReflectorClusterID: " + cluster_id|string) not in calico_rr_node.stdout_lines' + set_fact: + calico_rr_node_patched: >- + {{ calico_rr_node.stdout | from_json | combine({ 'spec': { 'bgp': + { 'routeReflectorClusterID': cluster_id }}}, recursive=True) }} - name: Calico-rr | Configure route reflector - shell: |- - echo -e '{{ calico_rr_node.stdout }}' | - {{ bin_dir }}/calicoctl.sh replace -f- - retries: 4 - delay: "{{ retry_stagger | random + 3 }}" + shell: "{{ bin_dir }}/calicoctl.sh replace -f-" + args: + stdin: "{{ calico_rr_node_patched | to_json }}" - name: Calico-rr | Set label for route reflector command: >- {{ bin_dir }}/calicoctl.sh label node {{ inventory_hostname }} 'i-am-a-route-reflector=true' --overwrite - retries: 4 - delay: "{{ retry_stagger | random + 3 }}"