Skip to content
Snippets Groups Projects
main.yml 6.89 KiB
Newer Older
  • Learn to ignore specific revisions
  • - import_tasks: verify-settings.yml
    
    Bogdan Dobrelya's avatar
    Bogdan Dobrelya committed
    - name: Force binaries directory for Container Linux by CoreOS
    
      set_fact:
        bin_dir: "/opt/bin"
    
      when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
    
    ant31's avatar
    ant31 committed
    - name: check bin dir exists
      file:
        path: "{{bin_dir}}"
        state: directory
        owner: root
      become: true
    
    - import_tasks: set_facts.yml
    
    Smaine Kahlouch's avatar
    Smaine Kahlouch committed
    - name: gather os specific variables
      include_vars: "{{ item }}"
      with_first_found:
        - files:
    
            - "{{ ansible_distribution|lower }}-{{ ansible_distribution_version|lower|replace('/', '_') }}.yml"
            - "{{ ansible_distribution|lower }}-{{ ansible_distribution_release }}.yml"
            - "{{ ansible_distribution|lower }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
            - "{{ ansible_distribution|lower }}.yml"
            - "{{ ansible_os_family|lower }}.yml"
            - defaults.yml
    
    Smaine Kahlouch's avatar
    Smaine Kahlouch committed
          paths:
    
            - ../vars
    
    Smana's avatar
    Smana committed
          skip: true
    
    - name: Create kubernetes directories
    
        path: "{{ item }}"
    
        state: directory
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when: inventory_hostname in groups['k8s-cluster']
    
      tags:
        - kubelet
        - k8s-secrets
        - kube-controller-manager
        - kube-apiserver
        - bootstrap-os
        - apps
        - network
        - master
        - node
    
      with_items:
        - "{{ kube_config_dir }}"
        - "{{ kube_config_dir }}/ssl"
        - "{{ kube_manifest_dir }}"
        - "{{ kube_script_dir }}"
    
    - name: check cloud_provider value
      fail:
    
        msg: "If set the 'cloud_provider' var must be set either to 'generic', 'gce', 'aws', 'azure', 'openstack', 'vsphere', or external"
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when:
        - cloud_provider is defined
    
        - cloud_provider not in ['generic', 'gce', 'aws', 'azure', 'openstack', 'vsphere', 'external']
    
    - include_tasks: "{{ cloud_provider }}-credential-check.yml"
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when:
        - cloud_provider is defined
        - cloud_provider in [ 'openstack', 'azure', 'vsphere' ]
    
    - name: Create cni directories
      file:
        path: "{{ item }}"
        state: directory
    
      with_items:
        - "/etc/cni/net.d"
        - "/opt/cni/bin"
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when:
    
    melkosoft's avatar
    melkosoft committed
        - kube_network_plugin in ["calico", "weave", "canal", "flannel", "contiv", "cilium"]
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
        - inventory_hostname in groups['k8s-cluster']
    
    melkosoft's avatar
    melkosoft committed
        - cilium
    
        - contiv
    
    - import_tasks: resolvconf.yml
    
    pmontanari's avatar
    pmontanari committed
      when:
        - dns_mode != 'none'
        - resolvconf_mode == 'host_resolvconf'
      tags:
        - bootstrap-os
        - resolvconf
    
    
    - name: Update package management cache (YUM)
    
      yum:
        update_cache: yes
        name: '*'
    
      register: yum_task_result
      until: yum_task_result|succeeded
      retries: 4
      delay: "{{ retry_stagger | random + 3 }}"
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when:
        - ansible_pkg_mgr == 'yum'
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
        - not is_atomic
    
      tags: bootstrap-os
    
    - name: Expire management cache (YUM) for Updation - Redhat
      shell: yum clean expire-cache
      register: expire_cache_output
      until: expire_cache_output|succeeded
      retries: 4
      delay: "{{ retry_stagger | random + 3 }}"
      when:
        - ansible_pkg_mgr == 'yum'
        - ansible_distribution == 'RedHat'
        - not is_atomic
      tags: bootstrap-os
    
    - name: Update package management cache (YUM) - Redhat
      shell: yum makecache
      register: make_cache_output
      until: make_cache_output|succeeded
      retries: 4
      delay: "{{ retry_stagger | random + 3 }}"
      when:
        - ansible_pkg_mgr == 'yum'
        - ansible_distribution == 'RedHat'
        - expire_cache_output.rc == 0
        - not is_atomic
      tags: bootstrap-os
    
    
    - name: Update package management cache (APT)
    
      apt:
        update_cache: yes
        cache_valid_time: 3600
    
      when: ansible_os_family == "Debian"
    
    Smaine Kahlouch's avatar
    Smaine Kahlouch committed
    
    - name: Install python-dnf for latest RedHat versions
    
    Smana's avatar
    Smana committed
      command: dnf install -y python-dnf yum
    
      register: dnf_task_result
      until: dnf_task_result|succeeded
      retries: 4
      delay: "{{ retry_stagger | random + 3 }}"
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when:
        - ansible_distribution == "Fedora"
        - ansible_distribution_major_version > 21
    
        - not is_atomic
    
    Smaine Kahlouch's avatar
    Smaine Kahlouch committed
      changed_when: False
    
    Smana's avatar
    Smana committed
    - name: Install epel-release on RedHat/CentOS
    
      yum:
        name: epel-release
        state: present
    
    Matthew Mosesohn's avatar
    Matthew Mosesohn committed
      when:
        - ansible_distribution in ["CentOS","RedHat"]
        - not is_atomic
        - epel_enabled|bool
    
    Smaine Kahlouch's avatar
    Smaine Kahlouch committed
    - name: Install packages requirements
    
      action:
        module: "{{ ansible_pkg_mgr }}"
        name: "{{ item }}"
        state: latest
    
      register: pkgs_task_result
    
      until: pkgs_task_result|succeeded
    
      delay: "{{ retry_stagger | random + 3 }}"
    
    Smana's avatar
    Smana committed
      with_items: "{{required_pkgs | default([]) | union(common_required_pkgs|default([]))}}"
    
      when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] or is_atomic)
    
    Abel Lopez's avatar
    Abel Lopez committed
    - name: Confirm selinux deployed
      stat:
        path: /etc/selinux/config
      when: ansible_os_family == "RedHat"
      register: slc
    
    
    - name: Set selinux policy
    
        state: "{{ preinstall_selinux_state }}"
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when:
        - ansible_os_family == "RedHat"
        - slc.stat.exists == True
    
    - name: Disable IPv6 DNS lookup
      lineinfile:
        dest: /etc/gai.conf
        line: "precedence ::ffff:0:0/96  100"
        state: present
        backup: yes
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when:
        - disable_ipv6_dns
        - not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
    
    - name: set default sysctl file path
      set_fact:
        sysctl_file_path: "/etc/sysctl.d/99-sysctl.conf"
    
    
    - name: Stat sysctl file configuration
    
      stat:
        path: "{{sysctl_file_path}}"
    
      register: sysctl_file_stat
    
    
    - name: Change sysctl file path to link source if linked
      set_fact:
        sysctl_file_path: "{{sysctl_file_stat.stat.lnk_source}}"
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when:
        - sysctl_file_stat.stat.islnk is defined
        - sysctl_file_stat.stat.islnk
    
        sysctl_file: "{{sysctl_file_path}}"
    
        name: net.ipv4.ip_forward
        value: 1
    
    - import_tasks: etchosts.yml
    
    - import_tasks: dhclient-hooks.yml
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when:
        - dns_mode != 'none'
        - resolvconf_mode == 'host_resolvconf'
        - not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
    
    - import_tasks: dhclient-hooks-undo.yml
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when:
        - dns_mode != 'none'
        - resolvconf_mode != 'host_resolvconf'
        - not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
    
    - name: Check if we are running inside a Azure VM
    
      stat:
        path: /var/lib/waagent/
    
      register: azure_check
    
    - import_tasks: growpart-azure-centos-7.yml
    
    Sergii Golovatiuk's avatar
    Sergii Golovatiuk committed
      when:
        - azure_check.stat.exists
        - ansible_distribution in ["CentOS","RedHat"]