From da9da0896404d19ffefefeb1141b37810dfa659d Mon Sep 17 00:00:00 2001 From: Bogdan Dobrelya Date: Thu, 5 Jan 2017 16:32:08 +0100 Subject: [PATCH] Better fix for different CoreOS os family facts Signed-off-by: Bogdan Dobrelya --- roles/docker/handlers/main.yml | 2 +- roles/docker/tasks/main.yml | 8 ++++---- roles/docker/tasks/systemd.yml | 2 +- roles/download/tasks/main.yml | 8 ++++---- roles/etcd/meta/main.yml | 2 +- roles/etcd/tasks/gen_certs.yml | 2 +- roles/kubernetes/preinstall/handlers/main.yml | 8 ++++---- roles/kubernetes/preinstall/tasks/main.yml | 6 +++--- roles/kubernetes/preinstall/tasks/resolvconf.yml | 8 ++++---- roles/kubernetes/preinstall/tasks/set_resolv_facts.yml | 4 ++-- roles/kubernetes/secrets/tasks/gen_certs.yml | 2 +- roles/network_plugin/calico/rr/meta/main.yml | 2 +- roles/network_plugin/flannel/handlers/main.yml | 2 +- .../flannel/templates/flannel-options.conf.j2 | 2 +- tests/testcases/020_check-create-pod.yml | 4 ++-- tests/testcases/030_check-network.yml | 4 ++-- tests/testcases/040_check-network-adv.yml | 4 ++-- 17 files changed, 35 insertions(+), 35 deletions(-) diff --git a/roles/docker/handlers/main.yml b/roles/docker/handlers/main.yml index 360cc1bf2..e92bf3a51 100644 --- a/roles/docker/handlers/main.yml +++ b/roles/docker/handlers/main.yml @@ -15,7 +15,7 @@ service: name: docker.socket state: restarted - when: ansible_os_family == 'Container Linux by CoreOS' + when: ansible_os_family in ['CoreOS', 'Container Linux by CoreOS'] - name: Docker | reload docker service: diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index 4d7fe573e..4494ac611 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -20,7 +20,7 @@ docker requires a minimum kernel version of {{ docker_kernel_min_version }} on {{ ansible_distribution }}-{{ ansible_distribution_version }} - when: (ansible_os_family != "Container Linux by CoreOS") and (ansible_kernel|version_compare(docker_kernel_min_version, "<")) + when: (not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]) and (ansible_kernel|version_compare(docker_kernel_min_version, "<")) tags: facts - name: ensure docker repository public key is installed @@ -34,7 +34,7 @@ retries: 4 delay: "{{ retry_stagger | random + 3 }}" with_items: "{{ docker_repo_key_info.repo_keys }}" - when: ansible_os_family != "Container Linux by CoreOS" + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - name: ensure docker repository is enabled action: "{{ docker_repo_info.pkg_repo }}" @@ -42,7 +42,7 @@ repo: "{{item}}" state: present with_items: "{{ docker_repo_info.repos }}" - when: (ansible_os_family != "Container Linux by CoreOS") and (docker_repo_info.repos|length > 0) + when: (not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]) and (docker_repo_info.repos|length > 0) - name: Configure docker repository on RedHat/CentOS copy: @@ -61,7 +61,7 @@ retries: 4 delay: "{{ retry_stagger | random + 3 }}" with_items: "{{ docker_package_info.pkgs }}" - when: (ansible_os_family != "Container Linux by CoreOS") and (docker_package_info.pkgs|length > 0) + when: (not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]) and (docker_package_info.pkgs|length > 0) - name: Set docker systemd config include: systemd.yml diff --git a/roles/docker/tasks/systemd.yml b/roles/docker/tasks/systemd.yml index 5eb6e63e8..090641f85 100644 --- a/roles/docker/tasks/systemd.yml +++ b/roles/docker/tasks/systemd.yml @@ -13,7 +13,7 @@ src: docker.service.j2 dest: /etc/systemd/system/docker.service register: docker_service_file - when: ansible_os_family != "Container Linux by CoreOS" + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - name: Write docker options systemd drop-in template: diff --git a/roles/download/tasks/main.yml b/roles/download/tasks/main.yml index 158d262f3..2fb9434bf 100644 --- a/roles/download/tasks/main.yml +++ b/roles/download/tasks/main.yml @@ -119,7 +119,7 @@ delegate_to: "{{ download_delegate }}" register: saved run_once: true - when: (ansible_os_family != "Container Linux by CoreOS" or download_delegate == "localhost") and download_run_once|bool and download.enabled|bool and download.container|bool and (container_changed|bool or not img.stat.exists) + when: (not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] or download_delegate == "localhost") and download_run_once|bool and download.enabled|bool and download.container|bool and (container_changed|bool or not img.stat.exists) - name: Download | copy container images to ansible host synchronize: @@ -128,7 +128,7 @@ mode: pull delegate_to: localhost become: false - when: ansible_os_family != "Container Linux by CoreOS" and inventory_hostname == groups['kube-master'][0] and download_delegate != "localhost" and download_run_once|bool and download.enabled|bool and download.container|bool and saved.changed + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] and inventory_hostname == groups['kube-master'][0] and download_delegate != "localhost" and download_run_once|bool and download.enabled|bool and download.container|bool and saved.changed - name: Download | upload container images to nodes synchronize: @@ -141,10 +141,10 @@ until: get_task|success retries: 4 delay: "{{ retry_stagger | random + 3 }}" - when: (ansible_os_family != "Container Linux by CoreOS" and inventory_hostname != groups['kube-master'][0] or download_delegate == "localhost") and download_run_once|bool and download.enabled|bool and download.container|bool + when: (not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] and inventory_hostname != groups['kube-master'][0] or download_delegate == "localhost") and download_run_once|bool and download.enabled|bool and download.container|bool tags: [upload, upgrade] - name: Download | load container images shell: "{{ docker_bin_dir }}/docker load < {{ fname }}" - when: (ansible_os_family != "Container Linux by CoreOS" and inventory_hostname != groups['kube-master'][0] or download_delegate == "localhost") and download_run_once|bool and download.enabled|bool and download.container|bool + when: (not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] and inventory_hostname != groups['kube-master'][0] or download_delegate == "localhost") and download_run_once|bool and download.enabled|bool and download.container|bool tags: [upload, upgrade] diff --git a/roles/etcd/meta/main.yml b/roles/etcd/meta/main.yml index ad580afdd..addd81053 100644 --- a/roles/etcd/meta/main.yml +++ b/roles/etcd/meta/main.yml @@ -2,7 +2,7 @@ dependencies: - role: adduser user: "{{ addusers.etcd }}" - when: ansible_os_family != 'Container Linux by CoreOS' + when: not ansible_os_family in ['CoreOS', 'Container Linux by CoreOS'] - role: download file: "{{ downloads.etcd }}" tags: download diff --git a/roles/etcd/tasks/gen_certs.yml b/roles/etcd/tasks/gen_certs.yml index 8807fb626..be127e972 100644 --- a/roles/etcd/tasks/gen_certs.yml +++ b/roles/etcd/tasks/gen_certs.yml @@ -129,7 +129,7 @@ /usr/local/share/ca-certificates/etcd-ca.crt {%- elif ansible_os_family == "RedHat" -%} /etc/pki/ca-trust/source/anchors/etcd-ca.crt - {%- elif ansible_os_family == "Container Linux by CoreOS" -%} + {%- elif ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] -%} /etc/ssl/certs/etcd-ca.pem {%- endif %} tags: facts diff --git a/roles/kubernetes/preinstall/handlers/main.yml b/roles/kubernetes/preinstall/handlers/main.yml index 19a9770f3..f9586623f 100644 --- a/roles/kubernetes/preinstall/handlers/main.yml +++ b/roles/kubernetes/preinstall/handlers/main.yml @@ -3,7 +3,7 @@ notify: - Preinstall | reload network - Preinstall | reload kubelet - when: ansible_os_family != "Container Linux by CoreOS" + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] # FIXME(bogdando) https://github.com/projectcalico/felix/issues/1185 - name: Preinstall | reload network @@ -15,18 +15,18 @@ networking {%- endif %} state: restarted - when: ansible_os_family != "Container Linux by CoreOS" and kube_network_plugin not in ['canal', 'calico'] + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] and kube_network_plugin not in ['canal', 'calico'] - name: Preinstall | update resolvconf for Container Linux by CoreOS command: /bin/true notify: - Preinstall | apply resolvconf cloud-init - Preinstall | reload kubelet - when: ansible_os_family == "Container Linux by CoreOS" + when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - name: Preinstall | apply resolvconf cloud-init command: /usr/bin/coreos-cloudinit --from-file {{ resolveconf_cloud_init_conf }} - when: ansible_os_family == "Container Linux by CoreOS" + when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - name: Preinstall | reload kubelet service: diff --git a/roles/kubernetes/preinstall/tasks/main.yml b/roles/kubernetes/preinstall/tasks/main.yml index cab3f7b0c..0423ab93f 100644 --- a/roles/kubernetes/preinstall/tasks/main.yml +++ b/roles/kubernetes/preinstall/tasks/main.yml @@ -5,7 +5,7 @@ - name: Force binaries directory for Container Linux by CoreOS set_fact: bin_dir: "/opt/bin" - when: ansible_os_family == "Container Linux by CoreOS" + when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] tags: facts - name: check bin dir exists @@ -131,7 +131,7 @@ retries: 4 delay: "{{ retry_stagger | random + 3 }}" with_items: "{{required_pkgs | default([]) | union(common_required_pkgs|default([]))}}" - when: ansible_os_family != "Container Linux by CoreOS" + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] tags: bootstrap-os - name: Disable IPv6 DNS lookup @@ -140,7 +140,7 @@ line: "precedence ::ffff:0:0/96 100" state: present backup: yes - when: disable_ipv6_dns and ansible_os_family != "Container Linux by CoreOS" + when: disable_ipv6_dns and not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] tags: bootstrap-os # Todo : selinux configuration diff --git a/roles/kubernetes/preinstall/tasks/resolvconf.yml b/roles/kubernetes/preinstall/tasks/resolvconf.yml index a58d3eb99..c75f1dd86 100644 --- a/roles/kubernetes/preinstall/tasks/resolvconf.yml +++ b/roles/kubernetes/preinstall/tasks/resolvconf.yml @@ -1,7 +1,7 @@ --- - name: create temporary resolveconf cloud init file command: cp -f /etc/resolv.conf "{{ resolvconffile }}" - when: ansible_os_family == "Container Linux by CoreOS" + when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - name: Remove search/domain/nameserver options lineinfile: @@ -48,7 +48,7 @@ - name: get temporary resolveconf cloud init file content command: cat {{ resolvconffile }} register: cloud_config - when: ansible_os_family == "Container Linux by CoreOS" + when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - name: persist resolvconf cloud init file template: @@ -57,8 +57,8 @@ owner: root mode: 0644 notify: Preinstall | update resolvconf for Container Linux by CoreOS - when: ansible_os_family == "Container Linux by CoreOS" + when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - include: dhclient-hooks.yml - when: ansible_os_family != "Container Linux by CoreOS" + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] tags: [bootstrap-os, resolvconf] diff --git a/roles/kubernetes/preinstall/tasks/set_resolv_facts.yml b/roles/kubernetes/preinstall/tasks/set_resolv_facts.yml index 165ff7668..52f17600a 100644 --- a/roles/kubernetes/preinstall/tasks/set_resolv_facts.yml +++ b/roles/kubernetes/preinstall/tasks/set_resolv_facts.yml @@ -35,11 +35,11 @@ {%- if resolvconf|bool -%}/etc/resolvconf/resolv.conf.d/base{%- endif -%} head: >- {%- if resolvconf|bool -%}/etc/resolvconf/resolv.conf.d/head{%- endif -%} - when: ansible_os_family != "Container Linux by CoreOS" + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - name: target temporary resolvconf cloud init file (Container Linux by CoreOS) set_fact: resolvconffile=/tmp/resolveconf_cloud_init_conf - when: ansible_os_family == "Container Linux by CoreOS" + when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - name: target dhclient conf/hook files for Red Hat family set_fact: diff --git a/roles/kubernetes/secrets/tasks/gen_certs.yml b/roles/kubernetes/secrets/tasks/gen_certs.yml index da2ad6bcd..22116fd3d 100644 --- a/roles/kubernetes/secrets/tasks/gen_certs.yml +++ b/roles/kubernetes/secrets/tasks/gen_certs.yml @@ -74,7 +74,7 @@ /usr/local/share/ca-certificates/kube-ca.crt {%- elif ansible_os_family == "RedHat" -%} /etc/pki/ca-trust/source/anchors/kube-ca.crt - {%- elif ansible_os_family == "Container Linux by CoreOS" -%} + {%- elif ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] -%} /etc/ssl/certs/kube-ca.pem {%- endif %} tags: facts diff --git a/roles/network_plugin/calico/rr/meta/main.yml b/roles/network_plugin/calico/rr/meta/main.yml index 3721d8672..55104953e 100644 --- a/roles/network_plugin/calico/rr/meta/main.yml +++ b/roles/network_plugin/calico/rr/meta/main.yml @@ -1,6 +1,6 @@ dependencies: - role: etcd - role: docker - when: ansible_os_family != "Container Linux by CoreOS" + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - role: download file: "{{ downloads.calico_rr }}" diff --git a/roles/network_plugin/flannel/handlers/main.yml b/roles/network_plugin/flannel/handlers/main.yml index 8f265276c..82810ac98 100644 --- a/roles/network_plugin/flannel/handlers/main.yml +++ b/roles/network_plugin/flannel/handlers/main.yml @@ -20,7 +20,7 @@ service: name: docker.socket state: restarted - when: ansible_os_family == 'Container Linux by CoreOS' + when: ansible_os_family in ['CoreOS', 'Container Linux by CoreOS'] - name: Flannel | reload docker service: diff --git a/roles/network_plugin/flannel/templates/flannel-options.conf.j2 b/roles/network_plugin/flannel/templates/flannel-options.conf.j2 index df3862e38..9ee22b4bc 100644 --- a/roles/network_plugin/flannel/templates/flannel-options.conf.j2 +++ b/roles/network_plugin/flannel/templates/flannel-options.conf.j2 @@ -1,5 +1,5 @@ [Service] -{% if ansible_os_family == "Container Linux by CoreOS" %} +{% if ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] %} Environment="DOCKER_OPT_BIP=--bip={{ flannel_subnet }} --mtu={{ flannel_mtu }}" {% else %} Environment="DOCKER_NETWORK_OPTIONS=--bip={{ flannel_subnet }} --mtu={{ flannel_mtu }}" diff --git a/tests/testcases/020_check-create-pod.yml b/tests/testcases/020_check-create-pod.yml index d874374ea..d2e3e4341 100644 --- a/tests/testcases/020_check-create-pod.yml +++ b/tests/testcases/020_check-create-pod.yml @@ -10,11 +10,11 @@ - name: Force binaries directory for Container Linux by CoreOS set_fact: bin_dir: "/opt/bin" - when: ansible_os_family == "Container Linux by CoreOS" + when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - set_fact: bin_dir: "/usr/local/bin" - when: ansible_os_family != "Container Linux by CoreOS" + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - name: Run a replica controller composed of 2 pods shell: "{{bin_dir}}/kubectl run test --image={{test_image_repo}}:{{test_image_tag}} --replicas=2 --command -- tail -f /dev/null" diff --git a/tests/testcases/030_check-network.yml b/tests/testcases/030_check-network.yml index 30b9c0543..b92efa975 100644 --- a/tests/testcases/030_check-network.yml +++ b/tests/testcases/030_check-network.yml @@ -6,11 +6,11 @@ - name: Force binaries directory for Container Linux by CoreOS set_fact: bin_dir: "/opt/bin" - when: ansible_os_family == "Container Linux by CoreOS" + when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - set_fact: bin_dir: "/usr/local/bin" - when: ansible_os_family != "Container Linux by CoreOS" + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - name: Get pod names shell: "{{bin_dir}}/kubectl get pods -o json" diff --git a/tests/testcases/040_check-network-adv.yml b/tests/testcases/040_check-network-adv.yml index f32facb45..667707046 100644 --- a/tests/testcases/040_check-network-adv.yml +++ b/tests/testcases/040_check-network-adv.yml @@ -15,11 +15,11 @@ - name: Force binaries directory for Container Linux by CoreOS set_fact: bin_dir: "/opt/bin" - when: ansible_os_family == "Container Linux by CoreOS" + when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - set_fact: bin_dir: "/usr/local/bin" - when: ansible_os_family != "Container Linux by CoreOS" + when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] - name: Wait for netchecker server shell: "{{ bin_dir }}/kubectl get pods --namespace {{netcheck_namespace}} | grep ^netchecker-server"