From 7bdf3cad973bdc98d4f9a910c1a9a1f2b29d68b7 Mon Sep 17 00:00:00 2001 From: apaudy028 Date: Fri, 21 May 2021 10:23:34 -0600 Subject: [PATCH 01/28] first draft- updates in dataset_loader --- .../dataset_loader/tasks/dataset_loader.yml | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 0a5f88f640..49ce2f6bcb 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -693,6 +693,47 @@ set_fact: status_assignment: "{{ status_assignment | default({}) | combine({ item: 'REPORTED' }) }}" with_items: "{{ dl_hosts_atsec + dl_hosts_atsmid + dl_hosts_grove }}" + +- name: Set interface facts + set_fact: + all_available_interfaces: "{{ all_available_interfaces | default({}) | combine({ item : host_iface }) }}" + with_items: "{{ dl_hosts_all | difference(dl_hosts_mso_alias) }}" + vars: + host_iface: + avail_ifaces: "{{ hostvars[item]['ansible_interfaces'] }}" + +- name: debugging + debug: + msg: "{{ item.value.avail_ifaces }}" + with_items: "{{ all_available_interfaces | dict2items }}" + +- name: set fact for active interfaces + set_fact: + +- name: failig + debug: + msg: "failing for now" + failed_when: testing is not defined + +- name: Get default ip information each host + set_fact: + all_interfaces: "{{ all_interfaces | default([]) | combine({ item : [interfaces] }) }}" + with_items: "{{ dl_hosts_all | difference(dl_hosts_mso_alias) }}" + vars: + ip_v4: "{{ hostvars[item].ansible_default_ipv4.address }}/{{ hostvars[item].ansible_default_ipv4.netmask }}" + ipv4_cidr: "{{ ip_v4 | ipaddr('prefix') }}" + interfaces: + name: "{{ hostvars[item].ansible_default_ipv4.interface }}" + maxBandwidth: null + monitor: true + mtu: "{{ hostvars[item].ansible_default_ipv4.mtu }}" + ipAddresses: + - address: "{{ hostvars[item].ansible_default_ipv4.address }}/{{ ipv4_cidr }}" + gateway: "{{ hostvars[item].ansible_default_ipv4.gateway }}" + serviceAddress: true + - address: "{{ hostvars[item].ansible_default_ipv6.address }}/{{ hostvars[item].ansible_default_ipv6.prefix }}" + gateway: "{{ hostvars[item].ansible_default_ipv6.gateway }}" + serviceAddress: true - name: Create Servers (Non-mso) uri: From f8c3bd9999420fd5a26fbeaf380bebe6febb5264 Mon Sep 17 00:00:00 2001 From: apaudy028 Date: Mon, 24 May 2021 11:43:04 -0600 Subject: [PATCH 02/28] updates to API endpoints --- infrastructure/ansible/roles/to_api/tasks/snapshot.yml | 3 ++- infrastructure/ansible/sample.lab/ansible/vars.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/infrastructure/ansible/roles/to_api/tasks/snapshot.yml b/infrastructure/ansible/roles/to_api/tasks/snapshot.yml index 66148ee894..596c4455ef 100644 --- a/infrastructure/ansible/roles/to_api/tasks/snapshot.yml +++ b/infrastructure/ansible/roles/to_api/tasks/snapshot.yml @@ -50,7 +50,8 @@ - name: "Take pre-install snapshot of CRConfig.json ({{ to_api_target_cdn }})" delegate_to: localhost uri: - url: "{{ to_api_base_url }}/api/4.0/cdns/{{ to_api_target_cdn }}/snapshot" + url + url: "{{ to_api_base_url }}/api/{{ to_api_version }}/cdns/{{ to_api_target_cdn }}/snapshot" method: GET follow_redirects: all return_content: yes diff --git a/infrastructure/ansible/sample.lab/ansible/vars.yml b/infrastructure/ansible/sample.lab/ansible/vars.yml index 30036ada32..68131b302f 100644 --- a/infrastructure/ansible/sample.lab/ansible/vars.yml +++ b/infrastructure/ansible/sample.lab/ansible/vars.yml @@ -25,7 +25,7 @@ grovetccfg_version: "{{ grove_version }}" influxdb_relay_version: adaa2ea-1 feigner_version: 1.0.0_dev_11248-1 ats_version: 7.1.4-2.el7 -to_api_version: "2.0" +to_api_version: "3.0" todb_username: traffic_ops todb_db_name: traffic_ops From b2d791bc294e4bfe020caf31f008ef4c02ddc3ef Mon Sep 17 00:00:00 2001 From: apaudy028 Date: Fri, 4 Jun 2021 11:12:29 -0600 Subject: [PATCH 03/28] adding interfaces.j2 file for interface templating --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 4 ++++ .../ansible/roles/dataset_loader/templates/interfaces.j2 | 0 2 files changed, 4 insertions(+) create mode 100644 infrastructure/ansible/roles/dataset_loader/templates/interfaces.j2 diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 49ce2f6bcb..39e2272052 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -701,6 +701,10 @@ vars: host_iface: avail_ifaces: "{{ hostvars[item]['ansible_interfaces'] }}" + +- name: testing this out + template: src=./interfaces.j2 dest=./output.txt + with_items: "{{ all_available_interfaces }}" - name: debugging debug: diff --git a/infrastructure/ansible/roles/dataset_loader/templates/interfaces.j2 b/infrastructure/ansible/roles/dataset_loader/templates/interfaces.j2 new file mode 100644 index 0000000000..e69de29bb2 From 2931c1d51bdb87ab82151d79bbba80861612544f Mon Sep 17 00:00:00 2001 From: apaudy028 Date: Fri, 4 Jun 2021 11:14:32 -0600 Subject: [PATCH 04/28] adding content of interface jinja file --- .../dataset_loader/templates/interfaces.j2 | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/infrastructure/ansible/roles/dataset_loader/templates/interfaces.j2 b/infrastructure/ansible/roles/dataset_loader/templates/interfaces.j2 index e69de29bb2..bc802ce674 100644 --- a/infrastructure/ansible/roles/dataset_loader/templates/interfaces.j2 +++ b/infrastructure/ansible/roles/dataset_loader/templates/interfaces.j2 @@ -0,0 +1,22 @@ +{# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#} +{ +{% for interface in all_available_interfaces %} +{% set available_interface = interface[] %} +{% if hostvars[item][ansible_|join(available_interface[loop.index])].active == true %} + interface interface.value{{ loop.index }} is active +{% endif %} + +{% endfor %} +} \ No newline at end of file From 4735c76c5c5e5c916456ab7064a698e819715f46 Mon Sep 17 00:00:00 2001 From: apaudy028 Date: Fri, 25 Jun 2021 17:42:10 -0600 Subject: [PATCH 05/28] updating tasks to accout for changes in server interfaces endpoint in API 3.0 --- .../dataset_loader/tasks/dataset_loader.yml | 140 ++++++++++++++++-- .../dataset_loader/templates/interfaces.j2 | 22 --- .../roles/dataset_loader/templates/server.j2 | 7 +- 3 files changed, 132 insertions(+), 37 deletions(-) delete mode 100644 infrastructure/ansible/roles/dataset_loader/templates/interfaces.j2 diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 39e2272052..3b186f16cc 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -738,6 +738,136 @@ - address: "{{ hostvars[item].ansible_default_ipv6.address }}/{{ hostvars[item].ansible_default_ipv6.prefix }}" gateway: "{{ hostvars[item].ansible_default_ipv6.gateway }}" serviceAddress: true + +- name: set tmp var to store all pertinent interfaces data from ansible facts for each host + set_fact: + _dl_all_ifaces_tmp_1: "{{ (_dl_all_ifaces_tmp_1 | default([])) + [ifaces] }}" + loop: "{{ hostvars | to_json | replace(replacestr, '') | from_json | json_query(loop_query) | subelements('all_ifaces') }}" + loop_control: + label: "{{ item.0.host_name }} - {{ item.1 }}" + when: 'ifaces != ""' + vars: + loop_query: "* | [].{host_name: inventory_hostname, hostvrs: @, all_ifaces: @.ansible_interfaces || `[]`}" # || used to set default value to empty list + replacestr: "{{ '{{' }}" + iface_query: "[ansible_{{ item.1 }}] | [? (ipv4 || ipv6) && length(ipv6[?!starts_with(address,`fe80`) && scope == `global`]) > `0` && (type == `ether` || type == `bonding`)] | [0] | {iface_name: device, v6_addresses: ipv6[?!starts_with(address,`fe80`) && scope == `global`], host: `{{ item.0.host_name }}`, mtu: mtu, v4_address: ipv4}" + ifaces: "{{ item.0.hostvrs | json_query(iface_query) }}" + +- name: set var to add checks for v6 slaac address and service address to tmp var for all interfaces + set_fact: + _dl_all_ifaces_tmp_2: "{{ _dl_all_ifaces_tmp_2 | default({}) | combine({ host_key: combined_result }) }}" + loop: "{{ _dl_all_ifaces_tmp_1 | subelements('v6_addresses') }}" + loop_control: + label: "{{ item.0.host }} - {{item.1.address}}" + vars: + v6_start: "{{ (item.1.address.split(':')[:-1]) | join(':') }}" + v6_start_regex: "{{ v6_start }}.+" + v6_addr_list: "{{ item.0.v6_addresses | difference([item.1]) | map(attribute='address') | list }}" + v6_addr_starts_with: "{{ v6_addr_list | select('match',v6_start_regex) | list }}" + is_v6_slaac_addr: "{{ true if (v6_addr_list | length > 0) and ( v6_addr_list | select('match',v6_start_regex) | list | length == 0) else false }}" + default_v6_addr: "{{ hostvars[item.0.host].ipv6_service_address | default(hostvars[item.0.host].ansible_default_ipv6.address) }}" + is_v6_service_addr: "{{ true if ((item.1.address == default_v6_addr) and (( v6_addr_list | length ) == 0)) or (not is_v6_slaac_addr and ( v6_addr_list | length ) > 0) else false }}" + tmp_host_key: "{{ item.0.host }}.{{ item.0.iface_name}}" + host_key: "{{ tmp_host_key | replace('.','_') | replace('-','_') }}" # parsing error using '.' in host_key + result: "{{ item.1 | combine({'is_v6_slaac_addr': is_v6_slaac_addr, 'is_service_address': is_v6_service_addr}) }}" + host_query: "{{ host_key }}.host | [0]" + iface_query: "{{ host_key }}.iface_name | [0]" + mtu_query: "{{ host_key }}.mtu | [0]" + v4_addr_query: "{{ host_key }}.v4_address | [0]" + v6_addr_query: "{{ host_key }}.v6_addresses" + combined_result: + host: "{{ (_dl_all_ifaces_tmp_2 | default({})) | json_query(host_query) | default(item.0.host, true) }}" + iface_name: "{{ (_dl_all_ifaces_tmp_2 | default({})) | json_query(iface_query) | default(item.0.iface_name, true) }}" + mtu: "{{ (_dl_all_ifaces_tmp_2 | default({})) | json_query(mtu_query) | default(item.0.mtu, true) }}" + v4_address: "{{ (_dl_all_ifaces_tmp_2 | default({})) | json_query(v4_addr_query) | default(item.0.v4_address, true) }}" + v6_addresses: "{{ ((_dl_all_ifaces_tmp_2 | default({})) | json_query(v6_addr_query) | default([], true)) + [result] }}" + +- name: set var to add v4 service address check to tmp var for all interfaces + set_fact: + _dl_all_ifaces_tmp_3: "{{ (_dl_all_ifaces_tmp_3 | default([])) + [ item | combine({'v4_address': {'is_service_address': is_v4_service_addr } }, recursive=True)] }}" + loop: "{{ _dl_all_ifaces_tmp_2 | dict2items | map(attribute='value') | list }}" + loop_control: + label: "{{ item.host }} - {{ item.iface_name }}" + vars: + is_v4_service_addr: "{{ true if item.v4_address.address == hostvars[item.host].ansible_default_ipv4.address else false }}" + +- name: Get ip gateway information from shell + shell: "if [ \"$(`which ip` -{{ item.ip_family }} route show {{ item.address }}/{{ item.suffix }} | grep via)\" == \"\" ]; then `which ip` -{{ item.ip_family }} route show | grep default | grep -vE ' fe80| 127.' | cut -f3 -d' ';else `which ip` -{{ item.ip_family }} route show {{ item.address }}/{{ item.suffix }} | cut -f3 -d' '; fi" + loop: "{{ _dl_all_ifaces_tmp_3 | json_query(ipObject_query) }}" + register: ipAddress_gateways + changed_when: false + environment: + PATH: "{{ lookup('env', 'PATH') }}:/usr/local/sbin:/usr/sbin:/sbin" + vars: + ipObject_query: "[] | { v4_address: [].{ host: host, address: v4_address.address, suffix: v4_address.netmask, ip_family: `4` }, v6_addresses: [].{ address: @.v6_addresses[0].address, host: host, suffix: @.v6_addresses[0].prefix, ip_family: `6` } } | *[]" + delegate_to: "{{ item.host }}" + +- name: Get interface speed to determine max maxBandwidth + shell: "cat /sys/class/net/{{ item.iface_name }}/speed" + loop: "{{ _dl_all_ifaces_tmp_3 | json_query(iface_query) }}" + register: iface_total_bandwidth + changed_when: false + environment: + PATH: "{{ lookup('env', 'PATH') }}:/usr/local/sbin:/usr/sbin:/sbin" + vars: + iface_query: "[].{ host: host, iface_name: iface_name }" + failed_when: false + delegate_to: "{{ item.host }}" + +- name: Set var for adding v6 gateway information to to tmp var for all interfaces + set_fact: + _dl_all_ifaces_tmp_4: "{{ _dl_all_ifaces_tmp_4 | default({}) | combine({ hostAsKey: combined_result }) }}" + loop: "{{ _dl_all_ifaces_tmp_3 | subelements('v6_addresses') }}" + loop_control: + label: "{{ item.0.host }} - {{ item.1.address }}" + vars: + v6gateway_query: "[?item.address == `{{ item.1.address }}`] |[0].stdout" + v6gateway: "{{ (((ipAddress_gateways.results | json_query(v6gateway_query)) if ipAddress_gateways.results | json_query(v6gateway_query) != '' else (v6_cidr_address | ipaddr('1'))).split('/'))[0] }}" + v6_cidr_address: "{{ item.1.address }}/{{ item.1.prefix }}" + tmp_hostAsKey: "{{ item.0.host }}.{{ item.0.iface_name }}" + hostAsKey: "{{ tmp_hostAsKey | replace('.','_') | replace('-','_') }}" + result: "{{ item.1 | combine({'gateway': v6gateway, 'address': v6_cidr_address}) }}" + host_query: "{{ hostAsKey }}.host | [0]" + iface_query: "{{ hostAsKey }}.iface_name | [0]" + mtu_query: "{{ hostAsKey }}.mtu | [0]" + v4_address_query: "{{ hostAsKey }}.v4_address | [0]" + v6_addresses_query: "{{ hostAsKey }}.v6_addresses" + combined_result: + host: "{{ (_dl_all_ifaces_tmp_4 | default({})) | json_query(host_query) | default(item.0.host, true) }}" + iface_name: "{{ (_dl_all_ifaces_tmp_4 | default({})) | json_query(iface_query) | default(item.0.iface_name, true) }}" + mtu: "{{ (_dl_all_ifaces_tmp_4 | default({})) | json_query(mtu_query) | default(item.0.mtu, true) }}" + v4_address: "{{ (_dl_all_ifaces_tmp_4 | default({})) | json_query(v4_address_query) | default(item.0.v4_address, true) }}" + v6_addresses: "{{ ((_dl_all_ifaces_tmp_4 | default({})) | json_query(v6_addresses_query) | default([], true)) + [result] }}" + +- name: Set var to adding v4 gateway and interface total bandwidth to tmp var for all interfaces + set_fact: + _dl_all_ifaces_tmp_5: "{{ _dl_all_ifaces_tmp_5 | default ([]) + [item | combine({'iface_total_bandwidth': totalBandwidth, 'v4_address': {'gateway': v4gateway, 'address': v4_cidr_address } }, recursive=True)] }}" + loop: "{{ _dl_all_ifaces_tmp_4 | dict2items | map(attribute='value') | list }}" + loop_control: + label: "{{ item.host }} - {{ item.v4_address.address }}" + vars: + v4gateway_query: "[?item.address == `{{ item.v4_address.address}}`] |[0].stdout" + v4gateway: "{{ ((ipAddress_gateways.results | json_query(v4gateway_query)).split('/'))[0] }}" + v4_cidr_address: "{{ item.v4_address.address }}/{{ net_cidr_address | ipaddr('prefix') }}" + net_cidr_address: "{{ item.v4_address.network }}/{{ item.v4_address.netmask }}" + totalBandwidth_query: "[?item == `{{ item.iface_name }}`] | to_number([0].stdout)" + totalBandwidth: "{{ iface_total_bandwidth.results | json_query(totalBandwidth_query)}}" + +- name: Set Fact for all interfaces with required data for server creation + set_fact: + dl_all_interfaces: "{{ (dl_all_interfaces | default({})) | combine({ item.0.key: [serverIfacePayload] }, recursive=True, list_merge='append') }}" + loop: "{{ ifaceObject | subelements('value') }}" + loop_control: + label: "{{ item.0.key }} - {{ item.1.name }}" + vars: + ifaceObject_query: "[].{ key: host, value: [{name: iface_name, max_bandwidth: iface_total_bandwidth, mtu: to_number(mtu), ipAddresses: ({v4_address: [v4_address], v6_address: v6_addresses} | *[].{address: address, gateway: gateway, serviceAddress: is_service_address })}]}" + ifaceObject: "{{ _dl_all_ifaces_tmp_5 | json_query(ifaceObject_query) }}" + monitor_interface_query: "ipAddresses[] | [?serviceAddress == `true`]" + monitor_interface: "{{ true if (item.1 | json_query(monitor_interface_query) | length) > 0 else false }}" + serverIfacePayload: "{{ item.1 | combine({'monitor': monitor_interface, 'max_bandwidth': (max_bandwidth | int) }, recursive=True) }}" + bandwidth: "{{ (item.1.max_bandwidth | default(1000, true)) | int }}" + max_bandwidth_by_limit: "{{ bandwidth - (reserved_interface_bandwidth_lookup[bandwidth]) if reserved_interface_bandwidth_lookup is defined and reserved_interface_bandwidth_lookup[bandwidth] is defined }}" + max_bandwidth_by_percent: "{{ (bandwidth|int) - ((bandwidth|int)/(reserved_interface_bandwidth_percent | default(80) | int )) }}" + max_bandwidth: "{{ max_bandwidth_by_limit | default(max_bandwidth_by_percent,true) }}" - name: Create Servers (Non-mso) uri: @@ -776,15 +906,7 @@ profileId: "{{ profile_id }}" cdnId: "{{ cdn_id }}" updPending: True - interfaceName: "{{ hostvars[item].ansible_default_ipv4.interface | default('eth0') }}" - ipAddress: "{{ hostvars[item].ansible_default_ipv4.address | default(hostvars[item].ansible_host) }}" - ipIsService: true - ipNetmask: "{{ hostvars[item].ansible_default_ipv4.netmask | default('255.255.255.0') }}" - ipGateway: "{{ hostvars[item].ansible_default_ipv4.gateway | default('127.0.0.0') }}" - ip6Address: "{{ hostvars[item].not_autoconf_default_ipv6_address | default(hostvars[item].ansible_default_ipv6.address) | default(omit) }}" - ip6IsService: true - ip6Gateway: "{{ hostvars[item].ansible_default_ipv6.gateway | default(omit) }}" - interfaceMtu: "{{ hostvars[item].ansible_default_ipv4.mtu | default('9000') }}" + interfaces: "{{ dl_all_interfaces[item] }}" default_inventory_hostname: "{{ hostvars[item].component | default('server') }}.kabletown.invalid" merged_server_attrs: "{{ dl_ds_merged_servers['server.kabletown.invalid'] | combine(dl_ds_merged_servers[default_inventory_hostname] | default({}) ) | combine(dl_ds_merged_servers[item] | default({}) ) }}" tcpPort: "{{ merged_server_attrs.tcpPort | default(omit) }}" diff --git a/infrastructure/ansible/roles/dataset_loader/templates/interfaces.j2 b/infrastructure/ansible/roles/dataset_loader/templates/interfaces.j2 deleted file mode 100644 index bc802ce674..0000000000 --- a/infrastructure/ansible/roles/dataset_loader/templates/interfaces.j2 +++ /dev/null @@ -1,22 +0,0 @@ -{# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#} -{ -{% for interface in all_available_interfaces %} -{% set available_interface = interface[] %} -{% if hostvars[item][ansible_|join(available_interface[loop.index])].active == true %} - interface interface.value{{ loop.index }} is active -{% endif %} - -{% endfor %} -} \ No newline at end of file diff --git a/infrastructure/ansible/roles/dataset_loader/templates/server.j2 b/infrastructure/ansible/roles/dataset_loader/templates/server.j2 index 00abbcb14f..e2adf457d8 100644 --- a/infrastructure/ansible/roles/dataset_loader/templates/server.j2 +++ b/infrastructure/ansible/roles/dataset_loader/templates/server.j2 @@ -67,12 +67,7 @@ "hostName": "{{ hostName }}", "domainName": "{{ domainName }}", "cachegroupId": {{ cachegroupId }}, - "interfaceName": "{{ interfaceName }}", - "ipAddress": "{{ ipAddress }}", - "ipIsService": {{ ipIsService }}, - "ipNetmask": "{{ ipNetmask }}", - "ipGateway": "{{ ipGateway }}", - "interfaceMtu": {{ interfaceMtu }}, + "interfaces": {{ interfaces }}, "physLocationId": {{ physLocationId }}, "typeId": {{ typeId }}, "profileId": {{ profileId }}, From 8bd1dbbdab086160b4cc5da11007a15a0b37fdc2 Mon Sep 17 00:00:00 2001 From: apaudy028 Date: Mon, 12 Jul 2021 10:41:56 -0600 Subject: [PATCH 06/28] clean up and comments --- .../dataset_loader/tasks/dataset_loader.yml | 71 ++++--------------- 1 file changed, 15 insertions(+), 56 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 3b186f16cc..249a9132f5 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -694,52 +694,11 @@ status_assignment: "{{ status_assignment | default({}) | combine({ item: 'REPORTED' }) }}" with_items: "{{ dl_hosts_atsec + dl_hosts_atsmid + dl_hosts_grove }}" -- name: Set interface facts - set_fact: - all_available_interfaces: "{{ all_available_interfaces | default({}) | combine({ item : host_iface }) }}" - with_items: "{{ dl_hosts_all | difference(dl_hosts_mso_alias) }}" - vars: - host_iface: - avail_ifaces: "{{ hostvars[item]['ansible_interfaces'] }}" - -- name: testing this out - template: src=./interfaces.j2 dest=./output.txt - with_items: "{{ all_available_interfaces }}" - -- name: debugging - debug: - msg: "{{ item.value.avail_ifaces }}" - with_items: "{{ all_available_interfaces | dict2items }}" - -- name: set fact for active interfaces - set_fact: - -- name: failig - debug: - msg: "failing for now" - failed_when: testing is not defined - -- name: Get default ip information each host - set_fact: - all_interfaces: "{{ all_interfaces | default([]) | combine({ item : [interfaces] }) }}" - with_items: "{{ dl_hosts_all | difference(dl_hosts_mso_alias) }}" - vars: - ip_v4: "{{ hostvars[item].ansible_default_ipv4.address }}/{{ hostvars[item].ansible_default_ipv4.netmask }}" - ipv4_cidr: "{{ ip_v4 | ipaddr('prefix') }}" - interfaces: - name: "{{ hostvars[item].ansible_default_ipv4.interface }}" - maxBandwidth: null - monitor: true - mtu: "{{ hostvars[item].ansible_default_ipv4.mtu }}" - ipAddresses: - - address: "{{ hostvars[item].ansible_default_ipv4.address }}/{{ ipv4_cidr }}" - gateway: "{{ hostvars[item].ansible_default_ipv4.gateway }}" - serviceAddress: true - - address: "{{ hostvars[item].ansible_default_ipv6.address }}/{{ hostvars[item].ansible_default_ipv6.prefix }}" - gateway: "{{ hostvars[item].ansible_default_ipv6.gateway }}" - serviceAddress: true +# Due to data manipulation being a shortcome of ansible, in these next set of tasks we are extracting +# interface data that is needed for server creation for dual homing puposes from ansible facts and +# storing the final result in dl_all_interfaces var -- name: set tmp var to store all pertinent interfaces data from ansible facts for each host +- name: Set tmp var to store all pertinent interfaces data from ansible facts for each host set_fact: _dl_all_ifaces_tmp_1: "{{ (_dl_all_ifaces_tmp_1 | default([])) + [ifaces] }}" loop: "{{ hostvars | to_json | replace(replacestr, '') | from_json | json_query(loop_query) | subelements('all_ifaces') }}" @@ -752,7 +711,7 @@ iface_query: "[ansible_{{ item.1 }}] | [? (ipv4 || ipv6) && length(ipv6[?!starts_with(address,`fe80`) && scope == `global`]) > `0` && (type == `ether` || type == `bonding`)] | [0] | {iface_name: device, v6_addresses: ipv6[?!starts_with(address,`fe80`) && scope == `global`], host: `{{ item.0.host_name }}`, mtu: mtu, v4_address: ipv4}" ifaces: "{{ item.0.hostvrs | json_query(iface_query) }}" -- name: set var to add checks for v6 slaac address and service address to tmp var for all interfaces +- name: Set var to add checks for v6 slaac address and service address to tmp var for all interfaces set_fact: _dl_all_ifaces_tmp_2: "{{ _dl_all_ifaces_tmp_2 | default({}) | combine({ host_key: combined_result }) }}" loop: "{{ _dl_all_ifaces_tmp_1 | subelements('v6_addresses') }}" @@ -781,7 +740,7 @@ v4_address: "{{ (_dl_all_ifaces_tmp_2 | default({})) | json_query(v4_addr_query) | default(item.0.v4_address, true) }}" v6_addresses: "{{ ((_dl_all_ifaces_tmp_2 | default({})) | json_query(v6_addr_query) | default([], true)) + [result] }}" -- name: set var to add v4 service address check to tmp var for all interfaces +- name: Set var to add v4 service address check to tmp var for all interfaces set_fact: _dl_all_ifaces_tmp_3: "{{ (_dl_all_ifaces_tmp_3 | default([])) + [ item | combine({'v4_address': {'is_service_address': is_v4_service_addr } }, recursive=True)] }}" loop: "{{ _dl_all_ifaces_tmp_2 | dict2items | map(attribute='value') | list }}" @@ -975,15 +934,15 @@ profileId: "{{ profile_id }}" cdnId: "{{ cdn_id }}" updPending: True - interfaceName: "eth0" - ipIsService: true - ipAddress: "{{ hostvars[item].ansible_host }}" - ipNetmask: "255.255.255.0" - ipGateway: "127.0.0.0" - ip6Address: "{{ omit }}" - ip6IsService: true - ip6Gateway: "{{ omit }}" - interfaceMtu: "9000" + interfaces: + - maxBandwidth: null + monitor: true + mtu: 9000 + name: "eth0" + ipAddresses: + - address: "{{ hostvars[item].ansible_host }}" + gateway: "127.0.0.0" + serviceAddress: true default_inventory_hostname: "{{ hostvars[item].component | default('server') }}.kabletown.invalid" merged_server_attrs: "{{ dl_ds_merged_servers['server.kabletown.invalid'] | combine(dl_ds_merged_servers[default_inventory_hostname] | default({}) ) | combine(dl_ds_merged_servers[item] | default({}) ) }}" tcpPort: "{{ merged_server_attrs.tcpPort | default(omit) }}" From 4cc242cc49bc86cc978dad83f3eacc63772494bd Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Tue, 12 Apr 2022 08:35:47 -0600 Subject: [PATCH 07/28] update to task to get all cdns -- line 51 --- .../roles/dataset_loader/tasks/dataset_loader.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 249a9132f5..641b5c356b 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -50,20 +50,17 @@ - name: Update the Primary CDN uri: - url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/{{ existing_primary_cdn.id }}" + url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/{{ get_all_cdns.json | to_json | from_json | json_query(cdn_query) }}" method: PUT body: "{{ lookup('template', 'cdn.j2') }}" vars: name: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].name | default(cdnDelegationPrimary) }}" - domainName: "{{ cdnDelegationPrimary }}.{{ (dl_hosts_to | first).split('.')[1:] | join('.') | lower }}" + domainName: "{{ cdnDelegationPrimary }}.{{ (groups['traffic_ops'] | first).split('.')[1:] | join('.') | lower }}" dnssecEnabled: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].dnssecEnabled | default(false) | lower }}" + cdn_query: "response[?starts_with(domainName,`{{ cdnDelegationPrimary }}`) == `true`].id | [0]" error_query: "alerts[?level=='error'].text[?!contains(@,'already exists')]" - existing_primary_cdn: "{{ (get_all_cdns.json.response | to_json | lower | from_json) | selectattr('domainname', 'search', ('^'+cdnDelegationPrimary+'\\.')) | list | first }}" register: update_cdn_out failed_when: (update_cdn_out.status == 400 and update_cdn_out.json | to_json | from_json | json_query(error_query) | length != 0) or (update_cdn_out.status > 400 and update_cdn_out.status < 600) - no_log: true - retries: 10 - delay: 10 - name: Create additional CDNs having delegations uri: From 6d59747a0e9fa893b9f52feb456c4656eecdc367 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Tue, 12 Apr 2022 14:02:19 -0600 Subject: [PATCH 08/28] adding no_log for checking failure --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 641b5c356b..8a0ddd9cfe 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -61,6 +61,9 @@ error_query: "alerts[?level=='error'].text[?!contains(@,'already exists')]" register: update_cdn_out failed_when: (update_cdn_out.status == 400 and update_cdn_out.json | to_json | from_json | json_query(error_query) | length != 0) or (update_cdn_out.status > 400 and update_cdn_out.status < 600) + no_log: false + retries: 10 + delay: 10 - name: Create additional CDNs having delegations uri: From 13fc47c98e7b489da9e06a9bd749208652a92555 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 15 Apr 2022 14:12:21 -0600 Subject: [PATCH 09/28] line 51- datasetloader test --- .../roles/dataset_loader/tasks/dataset_loader.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 8a0ddd9cfe..66948b965a 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -44,24 +44,24 @@ url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns" method: GET register: get_all_cdns - no_log: true + no_log: false retries: 10 delay: 10 - name: Update the Primary CDN uri: - url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/{{ get_all_cdns.json | to_json | from_json | json_query(cdn_query) }}" + url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/{{ existing_primary_cdn.id }}" method: PUT body: "{{ lookup('template', 'cdn.j2') }}" vars: name: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].name | default(cdnDelegationPrimary) }}" - domainName: "{{ cdnDelegationPrimary }}.{{ (groups['traffic_ops'] | first).split('.')[1:] | join('.') | lower }}" + domainName: "{{ cdnDelegationPrimary }}.{{ (dl_hosts_to | first).split('.')[1:] | join('.') | lower }}" dnssecEnabled: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].dnssecEnabled | default(false) | lower }}" - cdn_query: "response[?starts_with(domainName,`{{ cdnDelegationPrimary }}`) == `true`].id | [0]" error_query: "alerts[?level=='error'].text[?!contains(@,'already exists')]" + existing_primary_cdn: "{{ (get_all_cdns.json.response | to_json | lower | from_json) | selectattr('domainname', 'search', ('^'+cdnDelegationPrimary+'\\.')) | list | first }}" register: update_cdn_out failed_when: (update_cdn_out.status == 400 and update_cdn_out.json | to_json | from_json | json_query(error_query) | length != 0) or (update_cdn_out.status > 400 and update_cdn_out.status < 600) - no_log: false + no_log: true retries: 10 delay: 10 From 7db9fcd4685bf805fa77c092703c6bc9e7a7ce8e Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 15 Apr 2022 16:07:59 -0600 Subject: [PATCH 10/28] log to test failed task --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 66948b965a..726fd6081e 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -61,7 +61,7 @@ existing_primary_cdn: "{{ (get_all_cdns.json.response | to_json | lower | from_json) | selectattr('domainname', 'search', ('^'+cdnDelegationPrimary+'\\.')) | list | first }}" register: update_cdn_out failed_when: (update_cdn_out.status == 400 and update_cdn_out.json | to_json | from_json | json_query(error_query) | length != 0) or (update_cdn_out.status > 400 and update_cdn_out.status < 600) - no_log: true + no_log: false retries: 10 delay: 10 From 02f8fd0503f4a87594500ed38eb48e578660fb45 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Mon, 18 Apr 2022 16:52:58 -0600 Subject: [PATCH 11/28] updating cdn.j2 to yml in dataset loader role --- .../ansible/roles/dataset_loader/defaults/main.yml | 6 ++++++ .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/defaults/main.yml b/infrastructure/ansible/roles/dataset_loader/defaults/main.yml index 987b634bab..5cc6082477 100644 --- a/infrastructure/ansible/roles/dataset_loader/defaults/main.yml +++ b/infrastructure/ansible/roles/dataset_loader/defaults/main.yml @@ -2061,3 +2061,9 @@ dl_ds_default_federations: - '::/0' ttl: 60 user: '{{ dl_ds_default_federation_user }}' + +# CDN +dl_cdn: + name: "{{ name }}" + domainName: "{{ domainName }}" + dnssecEnabled: "{{ dnssecEnabled }}" diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 726fd6081e..ccf36753f7 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -44,7 +44,7 @@ url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns" method: GET register: get_all_cdns - no_log: false + no_log: true retries: 10 delay: 10 @@ -52,7 +52,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/{{ existing_primary_cdn.id }}" method: PUT - body: "{{ lookup('template', 'cdn.j2') }}" + body: "{{ dl_cdn }}" vars: name: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].name | default(cdnDelegationPrimary) }}" domainName: "{{ cdnDelegationPrimary }}.{{ (dl_hosts_to | first).split('.')[1:] | join('.') | lower }}" @@ -61,7 +61,7 @@ existing_primary_cdn: "{{ (get_all_cdns.json.response | to_json | lower | from_json) | selectattr('domainname', 'search', ('^'+cdnDelegationPrimary+'\\.')) | list | first }}" register: update_cdn_out failed_when: (update_cdn_out.status == 400 and update_cdn_out.json | to_json | from_json | json_query(error_query) | length != 0) or (update_cdn_out.status > 400 and update_cdn_out.status < 600) - no_log: false + no_log: true retries: 10 delay: 10 @@ -69,7 +69,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns" method: POST - body: "{{ lookup('template', 'cdn.j2') }}" + body: "{{ dl_cdn }}" with_items: "{{ cdnDelegationList | difference(cdnDelegationPrimary) | intersect(dl_ds_merged_cdns | map('lower') | list) + cdnDelegationList | difference(dl_ds_merged_cdns | map('lower') | list)}}" vars: name: "{{ item.name | default(item) }}" From 2d94ab807524cb7f9bdf4ae9effb5df5e22c4576 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Tue, 19 Apr 2022 08:13:43 -0600 Subject: [PATCH 12/28] json syntax fix --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index ccf36753f7..265ebd4ed3 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -52,7 +52,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/{{ existing_primary_cdn.id }}" method: PUT - body: "{{ dl_cdn }}" + body: "{{ dl_cdn | from_json }}" vars: name: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].name | default(cdnDelegationPrimary) }}" domainName: "{{ cdnDelegationPrimary }}.{{ (dl_hosts_to | first).split('.')[1:] | join('.') | lower }}" @@ -69,7 +69,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns" method: POST - body: "{{ dl_cdn }}" + body: "{{ dl_cdn | from_json }}" with_items: "{{ cdnDelegationList | difference(cdnDelegationPrimary) | intersect(dl_ds_merged_cdns | map('lower') | list) + cdnDelegationList | difference(dl_ds_merged_cdns | map('lower') | list)}}" vars: name: "{{ item.name | default(item) }}" From 020cbef13f916504140b929cc9497b3b52abc1a7 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Tue, 19 Apr 2022 10:39:41 -0600 Subject: [PATCH 13/28] testing --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 265ebd4ed3..debadfad86 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -61,7 +61,7 @@ existing_primary_cdn: "{{ (get_all_cdns.json.response | to_json | lower | from_json) | selectattr('domainname', 'search', ('^'+cdnDelegationPrimary+'\\.')) | list | first }}" register: update_cdn_out failed_when: (update_cdn_out.status == 400 and update_cdn_out.json | to_json | from_json | json_query(error_query) | length != 0) or (update_cdn_out.status > 400 and update_cdn_out.status < 600) - no_log: true + no_log: false retries: 10 delay: 10 @@ -78,7 +78,7 @@ error_query: "alerts[?level=='error'].text[?!contains(@,'already exists')]" register: create_cdns_out failed_when: (create_cdns_out.status == 400 and create_cdns_out.json | to_json | from_json | json_query(error_query) | length != 0) or (create_cdns_out.status > 400 and create_cdns_out.status < 600) - no_log: true + no_log: false retries: 10 delay: 10 From a7540a169f2005dce105a0ffe5e536f9772118ba Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 29 Apr 2022 15:38:10 -0600 Subject: [PATCH 14/28] updating template module to copy for config in fake origin --- infrastructure/ansible/roles/fakeOrigin/tasks/fakeOrigin.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/ansible/roles/fakeOrigin/tasks/fakeOrigin.yml b/infrastructure/ansible/roles/fakeOrigin/tasks/fakeOrigin.yml index 7319cd4b23..3133d37c1a 100644 --- a/infrastructure/ansible/roles/fakeOrigin/tasks/fakeOrigin.yml +++ b/infrastructure/ansible/roles/fakeOrigin/tasks/fakeOrigin.yml @@ -24,8 +24,8 @@ delay: 5 - name: Copy config.json file - template: - src: "config.json.j2" + copy: + content: "{{ lookup('template', 'config.json.j2') | to_nice_json }}" dest: "{{ fo_conf_dir }}/config.json" owner: root group: root From 3869a3326cf46cdd4670bd69f0fa3fe5125afca9 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 29 Apr 2022 16:00:16 -0600 Subject: [PATCH 15/28] updating template module to copy for config in traffic ops --- .../ansible/roles/traffic_ops/tasks/traffic_ops.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml b/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml index afbeb276bf..d851b2a0ec 100644 --- a/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml +++ b/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml @@ -52,8 +52,8 @@ - name: Run Traffic Ops Postinstall block: - name: Render Traffic Ops Postinstall Answers - template: - src: "postinstall.input.j2" + copy: + content: "{{ lookup('template','postinstall.input.j2') | to_nice_json }}" owner: "{{ to_user }}" group: "{{ to_group }}" mode: 0600 From 1b676ab3b49ab41d9f4d2d6b9514a4f7035d7863 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Mon, 2 May 2022 11:33:29 -0600 Subject: [PATCH 16/28] updating plays to use template module --- .../ansible/roles/traffic_ops/tasks/traffic_ops.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml b/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml index d851b2a0ec..7616ed7155 100644 --- a/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml +++ b/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml @@ -52,8 +52,8 @@ - name: Run Traffic Ops Postinstall block: - name: Render Traffic Ops Postinstall Answers - copy: - content: "{{ lookup('template','postinstall.input.j2') | to_nice_json }}" + template: + src: postinstall.input.j2 owner: "{{ to_user }}" group: "{{ to_group }}" mode: 0600 From fb55badb6f086f39a4d8ca3aca837c3b279fbe4a Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 6 May 2022 09:13:34 -0600 Subject: [PATCH 17/28] updating plays to use j2 template for cdn.j2 --- .../ansible/roles/dataset_loader/defaults/main.yml | 6 ------ .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 8 ++++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/defaults/main.yml b/infrastructure/ansible/roles/dataset_loader/defaults/main.yml index 5cc6082477..987b634bab 100644 --- a/infrastructure/ansible/roles/dataset_loader/defaults/main.yml +++ b/infrastructure/ansible/roles/dataset_loader/defaults/main.yml @@ -2061,9 +2061,3 @@ dl_ds_default_federations: - '::/0' ttl: 60 user: '{{ dl_ds_default_federation_user }}' - -# CDN -dl_cdn: - name: "{{ name }}" - domainName: "{{ domainName }}" - dnssecEnabled: "{{ dnssecEnabled }}" diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index debadfad86..249a9132f5 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -52,7 +52,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/{{ existing_primary_cdn.id }}" method: PUT - body: "{{ dl_cdn | from_json }}" + body: "{{ lookup('template', 'cdn.j2') }}" vars: name: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].name | default(cdnDelegationPrimary) }}" domainName: "{{ cdnDelegationPrimary }}.{{ (dl_hosts_to | first).split('.')[1:] | join('.') | lower }}" @@ -61,7 +61,7 @@ existing_primary_cdn: "{{ (get_all_cdns.json.response | to_json | lower | from_json) | selectattr('domainname', 'search', ('^'+cdnDelegationPrimary+'\\.')) | list | first }}" register: update_cdn_out failed_when: (update_cdn_out.status == 400 and update_cdn_out.json | to_json | from_json | json_query(error_query) | length != 0) or (update_cdn_out.status > 400 and update_cdn_out.status < 600) - no_log: false + no_log: true retries: 10 delay: 10 @@ -69,7 +69,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns" method: POST - body: "{{ dl_cdn | from_json }}" + body: "{{ lookup('template', 'cdn.j2') }}" with_items: "{{ cdnDelegationList | difference(cdnDelegationPrimary) | intersect(dl_ds_merged_cdns | map('lower') | list) + cdnDelegationList | difference(dl_ds_merged_cdns | map('lower') | list)}}" vars: name: "{{ item.name | default(item) }}" @@ -78,7 +78,7 @@ error_query: "alerts[?level=='error'].text[?!contains(@,'already exists')]" register: create_cdns_out failed_when: (create_cdns_out.status == 400 and create_cdns_out.json | to_json | from_json | json_query(error_query) | length != 0) or (create_cdns_out.status > 400 and create_cdns_out.status < 600) - no_log: false + no_log: true retries: 10 delay: 10 From c6809cc8b58c4723641e97e3df24e0e71005f4a8 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 6 May 2022 09:35:41 -0600 Subject: [PATCH 18/28] checking logs --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 249a9132f5..dcaefe2556 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -61,7 +61,7 @@ existing_primary_cdn: "{{ (get_all_cdns.json.response | to_json | lower | from_json) | selectattr('domainname', 'search', ('^'+cdnDelegationPrimary+'\\.')) | list | first }}" register: update_cdn_out failed_when: (update_cdn_out.status == 400 and update_cdn_out.json | to_json | from_json | json_query(error_query) | length != 0) or (update_cdn_out.status > 400 and update_cdn_out.status < 600) - no_log: true + no_log: false retries: 10 delay: 10 @@ -78,7 +78,7 @@ error_query: "alerts[?level=='error'].text[?!contains(@,'already exists')]" register: create_cdns_out failed_when: (create_cdns_out.status == 400 and create_cdns_out.json | to_json | from_json | json_query(error_query) | length != 0) or (create_cdns_out.status > 400 and create_cdns_out.status < 600) - no_log: true + no_log: false retries: 10 delay: 10 From e915e5d172c9b9d4970a12ba58807463df846e89 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 6 May 2022 09:47:30 -0600 Subject: [PATCH 19/28] update to use defaults instead of j2 for unicode issue --- .../ansible/roles/dataset_loader/defaults/main.yml | 6 ++++++ .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/defaults/main.yml b/infrastructure/ansible/roles/dataset_loader/defaults/main.yml index 987b634bab..5cc6082477 100644 --- a/infrastructure/ansible/roles/dataset_loader/defaults/main.yml +++ b/infrastructure/ansible/roles/dataset_loader/defaults/main.yml @@ -2061,3 +2061,9 @@ dl_ds_default_federations: - '::/0' ttl: 60 user: '{{ dl_ds_default_federation_user }}' + +# CDN +dl_cdn: + name: "{{ name }}" + domainName: "{{ domainName }}" + dnssecEnabled: "{{ dnssecEnabled }}" diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index dcaefe2556..ebf11c71a3 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -52,7 +52,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/{{ existing_primary_cdn.id }}" method: PUT - body: "{{ lookup('template', 'cdn.j2') }}" + body: "{{ dl_cdn }}" vars: name: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].name | default(cdnDelegationPrimary) }}" domainName: "{{ cdnDelegationPrimary }}.{{ (dl_hosts_to | first).split('.')[1:] | join('.') | lower }}" @@ -69,7 +69,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns" method: POST - body: "{{ lookup('template', 'cdn.j2') }}" + body: "{{ dl_cdn }}" with_items: "{{ cdnDelegationList | difference(cdnDelegationPrimary) | intersect(dl_ds_merged_cdns | map('lower') | list) + cdnDelegationList | difference(dl_ds_merged_cdns | map('lower') | list)}}" vars: name: "{{ item.name | default(item) }}" From 42504342da74897b54d5269cf91a496dddf469ad Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 6 May 2022 10:11:23 -0600 Subject: [PATCH 20/28] to_nice_json update to var in line 51 --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index ebf11c71a3..6732c65849 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -52,7 +52,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/{{ existing_primary_cdn.id }}" method: PUT - body: "{{ dl_cdn }}" + body: "{{ dl_cdn | to_nice_json }}" vars: name: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].name | default(cdnDelegationPrimary) }}" domainName: "{{ cdnDelegationPrimary }}.{{ (dl_hosts_to | first).split('.')[1:] | join('.') | lower }}" @@ -69,7 +69,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns" method: POST - body: "{{ dl_cdn }}" + body: "{{ dl_cdn | to_nice_json }}" with_items: "{{ cdnDelegationList | difference(cdnDelegationPrimary) | intersect(dl_ds_merged_cdns | map('lower') | list) + cdnDelegationList | difference(dl_ds_merged_cdns | map('lower') | list)}}" vars: name: "{{ item.name | default(item) }}" From 33f14c54aef6a49b2382dc6b79cf5e0657ff24a1 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 6 May 2022 10:29:13 -0600 Subject: [PATCH 21/28] forcing bool type for var in dl_cdn --- infrastructure/ansible/roles/dataset_loader/defaults/main.yml | 2 +- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/defaults/main.yml b/infrastructure/ansible/roles/dataset_loader/defaults/main.yml index 5cc6082477..41d04c6cd3 100644 --- a/infrastructure/ansible/roles/dataset_loader/defaults/main.yml +++ b/infrastructure/ansible/roles/dataset_loader/defaults/main.yml @@ -2066,4 +2066,4 @@ dl_ds_default_federations: dl_cdn: name: "{{ name }}" domainName: "{{ domainName }}" - dnssecEnabled: "{{ dnssecEnabled }}" + dnssecEnabled: "{{ dnssecEnabled | bool }}" diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 6732c65849..ebf11c71a3 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -52,7 +52,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/{{ existing_primary_cdn.id }}" method: PUT - body: "{{ dl_cdn | to_nice_json }}" + body: "{{ dl_cdn }}" vars: name: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].name | default(cdnDelegationPrimary) }}" domainName: "{{ cdnDelegationPrimary }}.{{ (dl_hosts_to | first).split('.')[1:] | join('.') | lower }}" @@ -69,7 +69,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns" method: POST - body: "{{ dl_cdn | to_nice_json }}" + body: "{{ dl_cdn }}" with_items: "{{ cdnDelegationList | difference(cdnDelegationPrimary) | intersect(dl_ds_merged_cdns | map('lower') | list) + cdnDelegationList | difference(dl_ds_merged_cdns | map('lower') | list)}}" vars: name: "{{ item.name | default(item) }}" From 5849aa2124ffa5b08f779dc33820ee7329d1f420 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 6 May 2022 11:05:25 -0600 Subject: [PATCH 22/28] checking logs for create users task in dl --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index ebf11c71a3..41743eb1cd 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -61,7 +61,7 @@ existing_primary_cdn: "{{ (get_all_cdns.json.response | to_json | lower | from_json) | selectattr('domainname', 'search', ('^'+cdnDelegationPrimary+'\\.')) | list | first }}" register: update_cdn_out failed_when: (update_cdn_out.status == 400 and update_cdn_out.json | to_json | from_json | json_query(error_query) | length != 0) or (update_cdn_out.status > 400 and update_cdn_out.status < 600) - no_log: false + no_log: true retries: 10 delay: 10 @@ -78,7 +78,7 @@ error_query: "alerts[?level=='error'].text[?!contains(@,'already exists')]" register: create_cdns_out failed_when: (create_cdns_out.status == 400 and create_cdns_out.json | to_json | from_json | json_query(error_query) | length != 0) or (create_cdns_out.status > 400 and create_cdns_out.status < 600) - no_log: false + no_log: true retries: 10 delay: 10 @@ -172,7 +172,7 @@ tenantId: "{{ get_all_tenants.json | json_query(tenant_query) | default(omit) }}" username: "{{ item.username }}" register: create_user_out - no_log: true + no_log: false retries: 10 delay: 10 failed_when: (create_user_out.status == 400 and create_user_out.json | to_json | from_json | json_query(error_query) | length != 0) or (create_user_out.status > 400 and create_user_out.status < 600) From de63758540e4b0f928d7d9c29a6223779f7161a6 Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 6 May 2022 12:19:20 -0600 Subject: [PATCH 23/28] adding body_format option on create user task --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 41743eb1cd..4bc0933b8d 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -149,6 +149,7 @@ url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/users" method: POST body: "{{ lookup('template', 'user.j2') }}" + body_format: json with_items: "{{ dl_ds_merged_users }}" vars: role_query: "response[?name == '{{ item.role | default('read-only') }}'].id | [0]" From a5a23c1ae8b5241271aeef745c644b255d0a192e Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 6 May 2022 13:20:46 -0600 Subject: [PATCH 24/28] adding to_json to remove python unicode string issue --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 4bc0933b8d..3645dd5b1f 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -148,8 +148,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/users" method: POST - body: "{{ lookup('template', 'user.j2') }}" - body_format: json + body: "{{ lookup('template', 'user.j2') | to_json }}" with_items: "{{ dl_ds_merged_users }}" vars: role_query: "response[?name == '{{ item.role | default('read-only') }}'].id | [0]" From fbb351a18113f664fab7fabb08ce7b6de5a74aef Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Fri, 6 May 2022 13:46:26 -0600 Subject: [PATCH 25/28] adding to_nice_json to remove python unicode string issue --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 3645dd5b1f..f845a100b2 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -148,7 +148,7 @@ uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/users" method: POST - body: "{{ lookup('template', 'user.j2') | to_json }}" + body: "{{ lookup('template', 'user.j2') | to_nice_json }}" with_items: "{{ dl_ds_merged_users }}" vars: role_query: "response[?name == '{{ item.role | default('read-only') }}'].id | [0]" From 4314f4064e853adc53087f90e3e4aba68f1536cd Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Mon, 9 May 2022 12:32:16 -0600 Subject: [PATCH 26/28] debugging --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index f845a100b2..0199d6a7c8 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -144,6 +144,11 @@ delay: 10 until: get_all_types['status']|default(0) == 200 +- debug: + msg: "{{ dl_ds_merged_users }}" + +- fail: + - name: Create Users uri: url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/users" From 3f79d42f2bd6fe8321e395774acd2e78ea01b53f Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Tue, 10 May 2022 09:39:09 -0600 Subject: [PATCH 27/28] adding debug items line 147 --- .../dataset_loader/tasks/dataset_loader.yml | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 0199d6a7c8..4868391c74 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -145,7 +145,29 @@ until: get_all_types['status']|default(0) == 200 - debug: - msg: "{{ dl_ds_merged_users }}" + msg: "{{ lookup('template', 'user.j2') }}" + with_items: "{{ dl_ds_merged_users }}" + vars: + role_query: "response[?name == '{{ item.role | default('read-only') }}'].id | [0]" + tenant_query: "response[?name == '{{ item.tenant | default('root') }}'].id | [0]" + error_query: "alerts[?level=='error'].text[?!contains(@,'already exists')]" + user_password: "{{ item.password | default( lookup('password', '/dev/null length=32 chars=ascii_letters') ) }}" + addressLine1: "{{ item.addressLine1 | default(omit) }}" + addressLine2: "{{ item.addressLine2 | default(omit) }}" + city: "{{ item.city | default(omit) }}" + confirmLocalPasswd: "{{ user_password }}" + company: "{{ item.company | default(omit) }}" + email: "{{ item.email }}" + fullName: "{{ item.fullName }}" + localPasswd: "{{ user_password }}" + newUser: "{{ item.newUser | default(omit) }}" + phoneNumber: "{{ item.phoneNumber | default(omit) }}" + postalCode: "{{ item.postalCode | default(omit) }}" + publicSshKey: "{{ item.publicSshKey | default(omit) }}" + role: "{{ get_all_roles.json | json_query(role_query) }}" + stateOrProvince: "{{ item.stateOrProvince | default(omit) }}" + tenantId: "{{ get_all_tenants.json | json_query(tenant_query) | default(omit) }}" + username: "{{ item.username }}" - fail: From 7cd1f6c7955ae61a18259739e4103dfd0ecd1a1f Mon Sep 17 00:00:00 2001 From: Ashish Paudyal Date: Tue, 10 May 2022 10:13:47 -0600 Subject: [PATCH 28/28] adding debug items line 167 & 169 --- .../ansible/roles/dataset_loader/tasks/dataset_loader.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml index 4868391c74..7f07169a74 100644 --- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml +++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml @@ -164,9 +164,9 @@ phoneNumber: "{{ item.phoneNumber | default(omit) }}" postalCode: "{{ item.postalCode | default(omit) }}" publicSshKey: "{{ item.publicSshKey | default(omit) }}" - role: "{{ get_all_roles.json | json_query(role_query) }}" + role: "{{ get_all_roles.json | to_json | from_json | json_query(role_query) }}" stateOrProvince: "{{ item.stateOrProvince | default(omit) }}" - tenantId: "{{ get_all_tenants.json | json_query(tenant_query) | default(omit) }}" + tenantId: "{{ get_all_tenants.json | to_json | from_json | json_query(tenant_query) | default(omit) }}" username: "{{ item.username }}" - fail: