From e447d28df783816bc450a944ff07803130c55c3e Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Mon, 17 Jul 2023 17:30:37 -0400 Subject: [PATCH] chore: update ansible assertion formatting Signed-off-by: Devin Buhl --- bootstrap/tasks/validation/age.yaml | 5 +- bootstrap/tasks/validation/cloudflare.yaml | 20 +++---- bootstrap/tasks/validation/github.yaml | 18 +++---- bootstrap/tasks/validation/net.yaml | 63 +++++++++++----------- bootstrap/tasks/validation/vars.yaml | 14 +++-- 5 files changed, 57 insertions(+), 63 deletions(-) diff --git a/bootstrap/tasks/validation/age.yaml b/bootstrap/tasks/validation/age.yaml index 03a0d9fd..6cc52f61 100644 --- a/bootstrap/tasks/validation/age.yaml +++ b/bootstrap/tasks/validation/age.yaml @@ -6,7 +6,7 @@ - name: Check if age key file exists ansible.builtin.assert: - that: [result.stat.exists] + that: result.stat.exists success_msg: Age file ~/.config/sops/age/keys.txt exists fail_msg: Age file ~/.config/sops/age/keys.txt does not exist @@ -16,7 +16,6 @@ - name: Check if age public keys match ansible.builtin.assert: - that: - - "'{{ bootstrap_age_public_key }}' in age_contents" + that: bootstrap_age_public_key in age_contents success_msg: Age public key {{ bootstrap_age_public_key }} exists fail_msg: Age public key {{ bootstrap_age_public_key }} does not exist diff --git a/bootstrap/tasks/validation/cloudflare.yaml b/bootstrap/tasks/validation/cloudflare.yaml index ad240a91..4c2885eb 100644 --- a/bootstrap/tasks/validation/cloudflare.yaml +++ b/bootstrap/tasks/validation/cloudflare.yaml @@ -1,9 +1,9 @@ --- - name: Query Cloudflare zone ansible.builtin.uri: - url: "https://api.cloudflare.com/client/v4/zones?name={{ bootstrap_cloudflare_domain }}&status=active" + url: https://api.cloudflare.com/client/v4/zones?name={{ bootstrap_cloudflare_domain }}&status=active headers: - Authorization: "Bearer {{ bootstrap_cloudflare_token }}" + Authorization: Bearer {{ bootstrap_cloudflare_token }} Content-Type: application/json timeout: 5 return_content: true @@ -12,15 +12,15 @@ - name: Check if Cloudflare zone exists ansible.builtin.assert: - that: ["result.json.success == true"] - success_msg: "Cloudflare zone {{ bootstrap_cloudflare_domain }} exists" - fail_msg: "Cloudflare zone {{ bootstrap_cloudflare_domain }} does not exist" + that: result.json.success is true + success_msg: Cloudflare zone {{ bootstrap_cloudflare_domain }} exists + fail_msg: Cloudflare zone {{ bootstrap_cloudflare_domain }} does not exist - name: Query Cloudflared tunnel ansible.builtin.uri: - url: "https://api.cloudflare.com/client/v4/accounts/{{ bootstrap_cloudflare_account_tag }}/cfd_tunnel/{{ bootstrap_cloudflare_tunnel_id }}" + url: https://api.cloudflare.com/client/v4/accounts/{{ bootstrap_cloudflare_account_tag }}/cfd_tunnel/{{ bootstrap_cloudflare_tunnel_id }} headers: - Authorization: "Bearer {{ bootstrap_cloudflare_token }}" + Authorization: Bearer {{ bootstrap_cloudflare_token }} Content-Type: application/json timeout: 5 return_content: true @@ -29,6 +29,6 @@ - name: Check if Cloudflared tunnel exists ansible.builtin.assert: - that: ["result.json.success == true"] - success_msg: "Cloudflared tunnel {{ bootstrap_cloudflare_tunnel_id }} exists" - fail_msg: "Cloudflared tunnel {{ bootstrap_cloudflare_tunnel_id }} does not exist" + that: result.json.success is true + success_msg: Cloudflared tunnel {{ bootstrap_cloudflare_tunnel_id }} exists + fail_msg: Cloudflared tunnel {{ bootstrap_cloudflare_tunnel_id }} does not exist diff --git a/bootstrap/tasks/validation/github.yaml b/bootstrap/tasks/validation/github.yaml index d33609a7..e90b468e 100644 --- a/bootstrap/tasks/validation/github.yaml +++ b/bootstrap/tasks/validation/github.yaml @@ -1,7 +1,7 @@ --- - name: Query Github username ansible.builtin.uri: - url: "https://api.github.com/users/{{ bootstrap_github_username }}" + url: https://api.github.com/users/{{ bootstrap_github_username }} timeout: 5 return_content: true body_format: json @@ -9,14 +9,13 @@ - name: Check if username exists ansible.builtin.assert: - that: - - "result.json.login == '{{ bootstrap_github_username }}'" - success_msg: "Github user {{ bootstrap_github_username }} exists" - fail_msg: "Github user {{ bootstrap_github_username }} does not exist" + that: result.json.login == bootstrap_github_username + success_msg: Github user {{ bootstrap_github_username }} exists + fail_msg: Github user {{ bootstrap_github_username }} does not exist - name: Query Github repo ansible.builtin.uri: - url: "https://api.github.com/repos/{{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }}" + url: https://api.github.com/repos/{{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }} timeout: 5 return_content: true body_format: json @@ -24,7 +23,6 @@ - name: Check if repo exists ansible.builtin.assert: - that: - - "result.json.full_name == '{{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }}'" - success_msg: "Github repo {{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }} exists" - fail_msg: "Github repo {{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }} does not exist" + that: result.json.full_name == bootstrap_github_username + '/' + bootstrap_github_repository_name + success_msg: Github repo {{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }} exists + fail_msg: Github repo {{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }} does not exist diff --git a/bootstrap/tasks/validation/net.yaml b/bootstrap/tasks/validation/net.yaml index 1102a940..39bb5f38 100644 --- a/bootstrap/tasks/validation/net.yaml +++ b/bootstrap/tasks/validation/net.yaml @@ -2,16 +2,16 @@ - name: Verify master node count ansible.builtin.assert: that: - - "{{ bootstrap_nodes.master | length > 0 }}" - - "{{ bootstrap_nodes.master | length is odd }}" - success_msg: "Master node count {{ bootstrap_nodes.master | length }} is correct." - fail_msg: "Master node count {{ bootstrap_nodes.master | length }} is not greater than 0 or is not odd." + - bootstrap_nodes.master | length > 0 + - bootstrap_nodes.master | length is odd + success_msg: Master node count {{ bootstrap_nodes.master | length }} is correct. + fail_msg: Master node count {{ bootstrap_nodes.master | length }} is not greater than 0 or is not odd. - name: Verify node CIDR ansible.builtin.assert: - that: ["{{ bootstrap_node_cidr is ansible.utils.ipv4 }}"] - success_msg: "Node CIDR {{ bootstrap_node_cidr }} is valid." - fail_msg: "Node CIDR {{ bootstrap_node_cidr }} is invalid." + that: bootstrap_node_cidr is ansible.utils.ipv4 + success_msg: Node CIDR {{ bootstrap_node_cidr }} is valid. + fail_msg: Node CIDR {{ bootstrap_node_cidr }} is invalid. - name: Verify cluster CIDR is ipv4 OR ipv6 when: not bootstrap_ipv6_enabled | default(false) @@ -57,46 +57,45 @@ - name: Verify k8s_gateway ansible.builtin.assert: - that: ["{{ bootstrap_k8s_gateway_addr is ansible.utils.ipv4 }}"] - success_msg: "k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is valid." - fail_msg: "k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is invalid." + that: bootstrap_k8s_gateway_addr is ansible.utils.ipv4 + success_msg: k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is valid. + fail_msg: k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is invalid. - name: Verify k8s_gateway in node CIDR ansible.builtin.assert: - that: ["{{ bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_k8s_gateway_addr) }}"] - success_msg: "k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is within {{ bootstrap_node_cidr }}." - fail_msg: "k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is not within {{ bootstrap_node_cidr }}." + that: bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_k8s_gateway_addr) + success_msg: k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is within {{ bootstrap_node_cidr }}. + fail_msg: k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is not within {{ bootstrap_node_cidr }}. - name: Verify ingress-nginx ansible.builtin.assert: - that: ["{{ bootstrap_ingress_nginx_addr is ansible.utils.ipv4 }}"] - success_msg: "ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is valid." - fail_msg: "ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is invalid." + that: bootstrap_ingress_nginx_addr is ansible.utils.ipv4 + success_msg: ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is valid. + fail_msg: ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is invalid. - name: Verify ingress-nginx in node CIDR ansible.builtin.assert: - that: ["{{ bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_ingress_nginx_addr) }}"] - success_msg: "ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is within {{ bootstrap_node_cidr }}." - fail_msg: "ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is not within {{ bootstrap_node_cidr }}." + that: bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_ingress_nginx_addr) + success_msg: ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is within {{ bootstrap_node_cidr }}. + fail_msg: ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is not within {{ bootstrap_node_cidr }}. - name: Verify kube-vip ansible.builtin.assert: - that: ["{{ bootstrap_kube_vip_addr is ansible.utils.ipv4 }}"] - success_msg: "kube-vip address {{ bootstrap_kube_vip_addr }} is valid." - fail_msg: "kube-vip address {{ bootstrap_kube_vip_addr }} is invalid." + that: bootstrap_kube_vip_addr is ansible.utils.ipv4 + success_msg: kube-vip address {{ bootstrap_kube_vip_addr }} is valid. + fail_msg: kube-vip address {{ bootstrap_kube_vip_addr }} is invalid. - name: Verify kube-vip in node CIDR ansible.builtin.assert: - that: ["{{ bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_kube_vip_addr) }}"] - success_msg: "kube-vip address {{ bootstrap_kube_vip_addr }} is within {{ bootstrap_node_cidr }}." - fail_msg: "kube-vip address {{ bootstrap_kube_vip_addr }} is not within {{ bootstrap_node_cidr }}." + that: bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_kube_vip_addr) + success_msg: kube-vip address {{ bootstrap_kube_vip_addr }} is within {{ bootstrap_node_cidr }}. + fail_msg: kube-vip address {{ bootstrap_kube_vip_addr }} is not within {{ bootstrap_node_cidr }}. - name: Verify nodes are not the same IPs as k8s_gateway, ingress-nginx or kube-vip ansible.builtin.assert: - that: - - "{{ item.address not in (bootstrap_k8s_gateway_addr, bootstrap_ingress_nginx_addr, bootstrap_kube_vip_addr) }}" - success_msg: "Node address {{ item.address }} is different than k8s_gateway, ingress-nginx or kube-vip." - fail_msg: "Node address {{ item.address }} is not different than k8s_gateway, ingress-nginx or kube-vip." + that: item.address not in (bootstrap_k8s_gateway_addr, bootstrap_ingress_nginx_addr, bootstrap_kube_vip_addr) + success_msg: Node address {{ item.address }} is different than k8s_gateway, ingress-nginx or kube-vip. + fail_msg: Node address {{ item.address }} is not different than k8s_gateway, ingress-nginx or kube-vip. quiet: true loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}" loop_control: @@ -114,9 +113,9 @@ - name: Verify nodes are in node CIDR ansible.builtin.assert: - that: ["{{ bootstrap_node_cidr | ansible.utils.network_in_usable(item.address) }}"] - success_msg: "Node address {{ item.address }} is within {{ bootstrap_node_cidr }}." - fail_msg: "Node address {{ item.address }} is not within {{ bootstrap_node_cidr }}." + that: bootstrap_node_cidr | ansible.utils.network_in_usable(item.address) + success_msg: Node address {{ item.address }} is within {{ bootstrap_node_cidr }}. + fail_msg: Node address {{ item.address }} is not within {{ bootstrap_node_cidr }}. quiet: true loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}" loop_control: diff --git a/bootstrap/tasks/validation/vars.yaml b/bootstrap/tasks/validation/vars.yaml index d0732760..e0d34da0 100644 --- a/bootstrap/tasks/validation/vars.yaml +++ b/bootstrap/tasks/validation/vars.yaml @@ -2,10 +2,9 @@ - name: Verify required bootstrap vars are set ansible.builtin.assert: - that: - - "{{ item }} | default('', true) | trim != ''" - success_msg: "Required bootstrap var {{ item }} exists and is defined" - fail_msg: "Required bootstrap var {{ item }} does not exists or is not defined" + that: item | default('', true) | trim != '' + success_msg: Required bootstrap var {{ item }} exists and is defined + fail_msg: Required bootstrap var {{ item }} does not exists or is not defined loop: - bootstrap_github_username - bootstrap_github_repository_name @@ -27,10 +26,9 @@ - name: Verify bootstrap node names are valid ansible.builtin.assert: - that: - - "item.name is match('^[a-z0-9-]+$')" - success_msg: "Node name {{ item.name }} is valid" - fail_msg: "Node name {{ item.name }} is not valid" + that: item.name is match('^[a-z0-9-]+$') + success_msg: Node name {{ item.name }} is valid + fail_msg: Node name {{ item.name }} is not valid loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}" loop_control: label: "{{ item.name }}"