Only use stat get_checksum: yes when needed (#7270)

By default Ansible stat module compute checksum, list extended attributes and find mime type
To find all stat invocations that really use one of those:
git grep -F stat. | grep -vE 'stat.(islnk|exists|lnk_source|writeable)'

Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
This commit is contained in:
Etienne Champetier 2021-02-10 08:36:59 -05:00 committed by GitHub
parent 6450207713
commit de1d9df787
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 142 additions and 2 deletions

View file

@ -69,6 +69,9 @@
- name: Check presence of fastestmirror.conf - name: Check presence of fastestmirror.conf
stat: stat:
path: /etc/yum/pluginconf.d/fastestmirror.conf path: /etc/yum/pluginconf.d/fastestmirror.conf
get_attributes: no
get_checksum: no
get_mime: no
register: fastestmirror register: fastestmirror
# the fastestmirror plugin can actually slow down Ansible deployments # the fastestmirror plugin can actually slow down Ansible deployments

View file

@ -4,6 +4,9 @@
- name: Check that /etc/sysconfig/proxy file exists - name: Check that /etc/sysconfig/proxy file exists
stat: stat:
path: /etc/sysconfig/proxy path: /etc/sysconfig/proxy
get_attributes: no
get_checksum: no
get_mime: no
register: stat_result register: stat_result
- name: Create the /etc/sysconfig/proxy empty file - name: Create the /etc/sysconfig/proxy empty file

View file

@ -85,6 +85,9 @@
- name: Check presence of fastestmirror.conf - name: Check presence of fastestmirror.conf
stat: stat:
path: /etc/yum/pluginconf.d/fastestmirror.conf path: /etc/yum/pluginconf.d/fastestmirror.conf
get_attributes: no
get_checksum: no
get_mime: no
register: fastestmirror register: fastestmirror
# the fastestmirror plugin can actually slow down Ansible deployments # the fastestmirror plugin can actually slow down Ansible deployments

View file

@ -2,6 +2,9 @@
- name: check if fedora coreos - name: check if fedora coreos
stat: stat:
path: /run/ostree-booted path: /run/ostree-booted
get_attributes: no
get_checksum: no
get_mime: no
register: ostree register: ostree
- name: set is_ostree - name: set is_ostree

View file

@ -2,6 +2,9 @@
- name: check if fedora coreos - name: check if fedora coreos
stat: stat:
path: /run/ostree-booted path: /run/ostree-booted
get_attributes: no
get_checksum: no
get_mime: no
register: ostree register: ostree
- name: set is_ostree - name: set is_ostree
@ -94,6 +97,9 @@
- name: Check if already installed - name: Check if already installed
stat: stat:
path: "/bin/crio" path: "/bin/crio"
get_attributes: no
get_checksum: no
get_mime: no
register: need_bootstrap_crio register: need_bootstrap_crio
when: is_ostree when: is_ostree

View file

@ -9,6 +9,9 @@
- name: Check if binary exists - name: Check if binary exists
stat: stat:
path: "{{ crun_bin_dir }}/crun" path: "{{ crun_bin_dir }}/crun"
get_attributes: no
get_checksum: no
get_mime: no
register: crun_stat register: crun_stat
# TODO: use download_file.yml # TODO: use download_file.yml

View file

@ -2,6 +2,9 @@
- name: check if fedora coreos - name: check if fedora coreos
stat: stat:
path: /run/ostree-booted path: /run/ostree-booted
get_attributes: no
get_checksum: no
get_mime: no
register: ostree register: ostree
- name: set is_ostree - name: set is_ostree

View file

@ -24,6 +24,9 @@
- name: download_container | Determine if image is in cache - name: download_container | Determine if image is in cache
stat: stat:
path: "{{ image_path_cached }}" path: "{{ image_path_cached }}"
get_attributes: no
get_checksum: no
get_mime: no
delegate_to: localhost delegate_to: localhost
connection: local connection: local
delegate_facts: no delegate_facts: no

View file

@ -29,6 +29,9 @@
- name: Stat etcd v2 data directory - name: Stat etcd v2 data directory
stat: stat:
path: "{{ etcd_data_dir }}/member" path: "{{ etcd_data_dir }}/member"
get_attributes: no
get_checksum: no
get_mime: no
register: etcd_data_dir_member register: etcd_data_dir_member
- name: Backup etcd v2 data - name: Backup etcd v2 data

View file

@ -17,6 +17,9 @@
- name: "Check certs | Register ca and etcd admin/member certs on etcd hosts" - name: "Check certs | Register ca and etcd admin/member certs on etcd hosts"
stat: stat:
path: "{{ etcd_cert_dir }}/{{ item }}" path: "{{ etcd_cert_dir }}/{{ item }}"
get_attributes: no
get_checksum: yes
get_mime: no
register: etcd_member_certs register: etcd_member_certs
when: inventory_hostname in groups['etcd'] when: inventory_hostname in groups['etcd']
with_items: with_items:

View file

@ -9,6 +9,9 @@
- name: Check if etcdctl exist - name: Check if etcdctl exist
stat: stat:
path: "{{ bin_dir }}/etcdctl" path: "{{ bin_dir }}/etcdctl"
get_attributes: no
get_checksum: no
get_mime: no
register: stat_etcdctl register: stat_etcdctl
- block: - block:
@ -28,6 +31,9 @@
- name: Check if etcdctl still exist after version check - name: Check if etcdctl still exist after version check
stat: stat:
path: "{{ bin_dir }}/etcdctl" path: "{{ bin_dir }}/etcdctl"
get_attributes: no
get_checksum: no
get_mime: no
register: stat_etcdctl register: stat_etcdctl
- block: - block:

View file

@ -17,6 +17,9 @@
- name: Check if bash_completion.d folder exists # noqa 503 - name: Check if bash_completion.d folder exists # noqa 503
stat: stat:
path: "/etc/bash_completion.d/" path: "/etc/bash_completion.d/"
get_attributes: no
get_checksum: no
get_mime: no
register: stat_result register: stat_result
- name: Get helm completion - name: Get helm completion

View file

@ -2,6 +2,9 @@
- name: Check if secret for encrypting data at rest already exist - name: Check if secret for encrypting data at rest already exist
stat: stat:
path: "{{ kube_cert_dir }}/secrets_encryption.yaml" path: "{{ kube_cert_dir }}/secrets_encryption.yaml"
get_attributes: no
get_checksum: no
get_mime: no
register: secrets_encryption_file register: secrets_encryption_file
- name: Slurp secrets_encryption file if it exists - name: Slurp secrets_encryption file if it exists

View file

@ -2,6 +2,9 @@
- name: kubeadm | Check if old apiserver cert exists on host - name: kubeadm | Check if old apiserver cert exists on host
stat: stat:
path: "{{ kube_cert_dir }}/apiserver.pem" path: "{{ kube_cert_dir }}/apiserver.pem"
get_attributes: no
get_checksum: no
get_mime: no
register: old_apiserver_cert register: old_apiserver_cert
delegate_to: "{{ groups['kube-master'] | first }}" delegate_to: "{{ groups['kube-master'] | first }}"
run_once: true run_once: true
@ -24,12 +27,18 @@
- name: kubeadm | Check serviceaccount key - name: kubeadm | Check serviceaccount key
stat: stat:
path: "{{ kube_cert_dir }}/sa.key" path: "{{ kube_cert_dir }}/sa.key"
get_attributes: no
get_checksum: yes
get_mime: no
register: sa_key_before register: sa_key_before
run_once: true run_once: true
- name: kubeadm | Check if kubeadm has already run - name: kubeadm | Check if kubeadm has already run
stat: stat:
path: "/var/lib/kubelet/config.yaml" path: "/var/lib/kubelet/config.yaml"
get_attributes: no
get_checksum: no
get_mime: no
register: kubeadm_already_run register: kubeadm_already_run
- name: kubeadm | Delete old admin.conf - name: kubeadm | Delete old admin.conf
@ -211,6 +220,9 @@
- name: kubeadm | Check serviceaccount key again - name: kubeadm | Check serviceaccount key again
stat: stat:
path: "{{ kube_cert_dir }}/sa.key" path: "{{ kube_cert_dir }}/sa.key"
get_attributes: no
get_checksum: yes
get_mime: no
register: sa_key_after register: sa_key_after
run_once: true run_once: true

View file

@ -13,11 +13,17 @@
- name: Check if kubelet.conf exists - name: Check if kubelet.conf exists
stat: stat:
path: "{{ kube_config_dir }}/kubelet.conf" path: "{{ kube_config_dir }}/kubelet.conf"
get_attributes: no
get_checksum: no
get_mime: no
register: kubelet_conf register: kubelet_conf
- name: Check if kubeadm CA cert is accessible - name: Check if kubeadm CA cert is accessible
stat: stat:
path: "{{ kube_cert_dir }}/ca.crt" path: "{{ kube_cert_dir }}/ca.crt"
get_attributes: no
get_checksum: no
get_mime: no
register: kubeadm_ca_stat register: kubeadm_ca_stat
delegate_to: "{{ groups['kube-master'][0] }}" delegate_to: "{{ groups['kube-master'][0] }}"
run_once: true run_once: true

View file

@ -22,6 +22,9 @@
- name: haproxy | Get checksum from config - name: haproxy | Get checksum from config
stat: stat:
path: "{{ haproxy_config_dir }}/haproxy.cfg" path: "{{ haproxy_config_dir }}/haproxy.cfg"
get_attributes: no
get_checksum: yes
get_mime: no
register: haproxy_stat register: haproxy_stat
- name: haproxy | Write static pod - name: haproxy | Write static pod

View file

@ -22,6 +22,9 @@
- name: nginx-proxy | Get checksum from config - name: nginx-proxy | Get checksum from config
stat: stat:
path: "{{ nginx_config_dir }}/nginx.conf" path: "{{ nginx_config_dir }}/nginx.conf"
get_attributes: no
get_checksum: yes
get_mime: no
register: nginx_stat register: nginx_stat
- name: nginx-proxy | Write static pod - name: nginx-proxy | Write static pod

View file

@ -50,13 +50,21 @@
# FIXME(mattymo): Also restart for kubeadm mode # FIXME(mattymo): Also restart for kubeadm mode
- name: Preinstall | kube-apiserver configured - name: Preinstall | kube-apiserver configured
stat: path="{{ kube_manifest_dir }}/kube-apiserver.manifest" stat:
path: "{{ kube_manifest_dir }}/kube-apiserver.manifest"
get_attributes: no
get_checksum: no
get_mime: no
register: kube_apiserver_set register: kube_apiserver_set
when: inventory_hostname in groups['kube-master'] and dns_mode != 'none' and resolvconf_mode == 'host_resolvconf' when: inventory_hostname in groups['kube-master'] and dns_mode != 'none' and resolvconf_mode == 'host_resolvconf'
# FIXME(mattymo): Also restart for kubeadm mode # FIXME(mattymo): Also restart for kubeadm mode
- name: Preinstall | kube-controller configured - name: Preinstall | kube-controller configured
stat: path="{{ kube_manifest_dir }}/kube-controller-manager.manifest" stat:
path: "{{ kube_manifest_dir }}/kube-controller-manager.manifest"
get_attributes: no
get_checksum: no
get_mime: no
register: kube_controller_set register: kube_controller_set
when: inventory_hostname in groups['kube-master'] and dns_mode != 'none' and resolvconf_mode == 'host_resolvconf' when: inventory_hostname in groups['kube-master'] and dns_mode != 'none' and resolvconf_mode == 'host_resolvconf'

View file

@ -9,6 +9,9 @@
- name: check if booted with ostree - name: check if booted with ostree
stat: stat:
path: /run/ostree-booted path: /run/ostree-booted
get_attributes: no
get_checksum: no
get_mime: no
register: ostree register: ostree
- name: set is_fedora_coreos - name: set is_fedora_coreos
@ -59,6 +62,9 @@
- name: check if kubelet is configured - name: check if kubelet is configured
stat: stat:
path: "{{ kube_config_dir }}/kubelet.env" path: "{{ kube_config_dir }}/kubelet.env"
get_attributes: no
get_checksum: no
get_mime: no
register: kubelet_configured register: kubelet_configured
changed_when: false changed_when: false
@ -84,6 +90,9 @@
- name: check if /etc/dhclient.conf exists - name: check if /etc/dhclient.conf exists
stat: stat:
path: /etc/dhclient.conf path: /etc/dhclient.conf
get_attributes: no
get_checksum: no
get_mime: no
register: dhclient_stat register: dhclient_stat
- name: target dhclient conf file for /etc/dhclient.conf - name: target dhclient conf file for /etc/dhclient.conf
@ -94,6 +103,9 @@
- name: check if /etc/dhcp/dhclient.conf exists - name: check if /etc/dhcp/dhclient.conf exists
stat: stat:
path: /etc/dhcp/dhclient.conf path: /etc/dhcp/dhclient.conf
get_attributes: no
get_checksum: no
get_mime: no
register: dhcp_dhclient_stat register: dhcp_dhclient_stat
- name: target dhclient conf file for /etc/dhcp/dhclient.conf - name: target dhclient conf file for /etc/dhcp/dhclient.conf
@ -170,6 +182,9 @@
- name: check /usr readonly - name: check /usr readonly
stat: stat:
path: "/usr" path: "/usr"
get_attributes: no
get_checksum: no
get_mime: no
register: usr register: usr
- name: set alternate flexvolume path - name: set alternate flexvolume path

View file

@ -46,6 +46,9 @@
- name: Check if kubernetes kubeadm compat cert dir exists - name: Check if kubernetes kubeadm compat cert dir exists
stat: stat:
path: "{{ kube_cert_compat_dir }}" path: "{{ kube_cert_compat_dir }}"
get_attributes: no
get_checksum: no
get_mime: no
register: kube_cert_compat_dir_check register: kube_cert_compat_dir_check
when: when:
- inventory_hostname in groups['k8s-cluster'] - inventory_hostname in groups['k8s-cluster']

View file

@ -3,6 +3,9 @@
- name: Confirm selinux deployed - name: Confirm selinux deployed
stat: stat:
path: /etc/selinux/config path: /etc/selinux/config
get_attributes: no
get_checksum: no
get_mime: no
when: when:
- ansible_os_family == "RedHat" - ansible_os_family == "RedHat"
- "'Amazon' not in ansible_distribution" - "'Amazon' not in ansible_distribution"
@ -36,6 +39,9 @@
- name: Stat sysctl file configuration - name: Stat sysctl file configuration
stat: stat:
path: "{{ sysctl_file_path }}" path: "{{ sysctl_file_path }}"
get_attributes: no
get_checksum: no
get_mime: no
register: sysctl_file_stat register: sysctl_file_stat
tags: tags:
- bootstrap-os - bootstrap-os

View file

@ -92,6 +92,9 @@
- name: Check if we are running inside a Azure VM - name: Check if we are running inside a Azure VM
stat: stat:
path: /var/lib/waagent/ path: /var/lib/waagent/
get_attributes: no
get_checksum: no
get_mime: no
register: azure_check register: azure_check
when: when:
- not dns_late - not dns_late

View file

@ -2,6 +2,9 @@
- name: "Check_tokens | check if the tokens have already been generated on first master" - name: "Check_tokens | check if the tokens have already been generated on first master"
stat: stat:
path: "{{ kube_token_dir }}/known_tokens.csv" path: "{{ kube_token_dir }}/known_tokens.csv"
get_attributes: no
get_checksum: yes
get_mime: no
delegate_to: "{{ groups['kube-master'][0] }}" delegate_to: "{{ groups['kube-master'][0] }}"
register: known_tokens_master register: known_tokens_master
run_once: true run_once: true
@ -20,6 +23,9 @@
- name: "Check tokens | check if a cert already exists" - name: "Check tokens | check if a cert already exists"
stat: stat:
path: "{{ kube_token_dir }}/known_tokens.csv" path: "{{ kube_token_dir }}/known_tokens.csv"
get_attributes: no
get_checksum: yes
get_mime: no
register: known_tokens register: known_tokens
- name: "Check_tokens | Set 'sync_tokens' to true" - name: "Check_tokens | Set 'sync_tokens' to true"

View file

@ -2,6 +2,9 @@
- name: reset | check dummy0 network device - name: reset | check dummy0 network device
stat: stat:
path: /sys/class/net/dummy0 path: /sys/class/net/dummy0
get_attributes: no
get_checksum: no
get_mime: no
register: dummy0 register: dummy0
- name: reset | remove the network device created by calico - name: reset | remove the network device created by calico

View file

@ -2,6 +2,9 @@
- name: "reset | check if network device {{ iface }} is present" - name: "reset | check if network device {{ iface }} is present"
stat: stat:
path: "/sys/class/net/{{ iface }}" path: "/sys/class/net/{{ iface }}"
get_attributes: no
get_checksum: no
get_mime: no
register: device_remains register: device_remains
- name: "reset | remove network device {{ iface }}" - name: "reset | remove network device {{ iface }}"

View file

@ -2,6 +2,9 @@
- name: reset | check cni network device - name: reset | check cni network device
stat: stat:
path: /sys/class/net/cni0 path: /sys/class/net/cni0
get_attributes: no
get_checksum: no
get_mime: no
register: cni register: cni
- name: reset | remove the network device created by the flannel - name: reset | remove the network device created by the flannel
@ -11,6 +14,9 @@
- name: reset | check flannel network device - name: reset | check flannel network device
stat: stat:
path: /sys/class/net/flannel.1 path: /sys/class/net/flannel.1
get_attributes: no
get_checksum: no
get_mime: no
register: flannel register: flannel
- name: reset | remove the network device created by the flannel - name: reset | remove the network device created by the flannel

View file

@ -2,6 +2,9 @@
- name: reset | check kube-dummy-if network device - name: reset | check kube-dummy-if network device
stat: stat:
path: /sys/class/net/kube-dummy-if path: /sys/class/net/kube-dummy-if
get_attributes: no
get_checksum: no
get_mime: no
register: kube_dummy_if register: kube_dummy_if
- name: reset | remove the network device created by kube-router - name: reset | remove the network device created by kube-router
@ -11,6 +14,9 @@
- name: check kube-bridge exists - name: check kube-bridge exists
stat: stat:
path: /sys/class/net/kube-bridge path: /sys/class/net/kube-bridge
get_attributes: no
get_checksum: no
get_mime: no
register: kube_bridge_if register: kube_bridge_if
- name: reset | donw the network bridge create by kube-router - name: reset | donw the network bridge create by kube-router

View file

@ -68,6 +68,9 @@
- name: reset | check if crictl is present - name: reset | check if crictl is present
stat: stat:
path: "{{ bin_dir }}/crictl" path: "{{ bin_dir }}/crictl"
get_attributes: no
get_checksum: no
get_mime: no
register: crictl register: crictl
- name: reset | stop all cri containers - name: reset | stop all cri containers
@ -204,6 +207,9 @@
- name: reset | check kube-ipvs0 network device - name: reset | check kube-ipvs0 network device
stat: stat:
path: /sys/class/net/kube-ipvs0 path: /sys/class/net/kube-ipvs0
get_attributes: no
get_checksum: no
get_mime: no
register: kube_ipvs0 register: kube_ipvs0
- name: reset | Remove kube-ipvs0 - name: reset | Remove kube-ipvs0
@ -215,6 +221,9 @@
- name: reset | check nodelocaldns network device - name: reset | check nodelocaldns network device
stat: stat:
path: /sys/class/net/nodelocaldns path: /sys/class/net/nodelocaldns
get_attributes: no
get_checksum: no
get_mime: no
register: nodelocaldns_device register: nodelocaldns_device
- name: reset | Remove nodelocaldns - name: reset | Remove nodelocaldns

View file

@ -3,6 +3,9 @@
- name: Check if temp directory for {{ test_name }} exists - name: Check if temp directory for {{ test_name }} exists
stat: stat:
path: "/tmp/{{ test_name }}" path: "/tmp/{{ test_name }}"
get_attributes: no
get_checksum: no
get_mime: no
register: temp_dir_details register: temp_dir_details
- name: "Cleanup temp directory for {{ test_name }}" - name: "Cleanup temp directory for {{ test_name }}"