From 4e62fd382bea9819b177a4d40d417995ae397144 Mon Sep 17 00:00:00 2001 From: Joe Stuart Date: Fri, 24 Apr 2020 14:11:15 -0500 Subject: [PATCH] make minishift and k8s_objects external --- playbooks/roles/cleanup/tasks/cleanup.yml | 25 +----- playbooks/roles/k8s_objects/tasks/main.yml | 52 ------------- .../roles/minishift/tasks/init_minishift.yml | 51 ------------ .../minishift/tasks/install_minishift_bin.yml | 31 -------- playbooks/roles/minishift/tasks/main.yml | 78 ------------------- .../minishift/tasks/set_minishift_path.yml | 11 --- playbooks/roles/prereqs/tasks/check_os.yml | 10 --- .../prereqs/tasks/install_kvm_plugin.yml | 28 ------- .../prereqs/tasks/install_mac_pre_reqs.yml | 36 --------- .../prereqs/tasks/install_virtual_reqs.yml | 73 ----------------- playbooks/roles/prereqs/tasks/main.yml | 16 ---- .../roles/prereqs/tasks/setup_nested_virt.yml | 78 ------------------- playbooks/setup.yml | 2 +- requirements.yml | 11 +++ 14 files changed, 13 insertions(+), 489 deletions(-) delete mode 100644 playbooks/roles/k8s_objects/tasks/main.yml delete mode 100644 playbooks/roles/minishift/tasks/init_minishift.yml delete mode 100644 playbooks/roles/minishift/tasks/install_minishift_bin.yml delete mode 100644 playbooks/roles/minishift/tasks/main.yml delete mode 100644 playbooks/roles/minishift/tasks/set_minishift_path.yml delete mode 100644 playbooks/roles/prereqs/tasks/check_os.yml delete mode 100644 playbooks/roles/prereqs/tasks/install_kvm_plugin.yml delete mode 100644 playbooks/roles/prereqs/tasks/install_mac_pre_reqs.yml delete mode 100644 playbooks/roles/prereqs/tasks/install_virtual_reqs.yml delete mode 100644 playbooks/roles/prereqs/tasks/main.yml delete mode 100644 playbooks/roles/prereqs/tasks/setup_nested_virt.yml create mode 100644 requirements.yml diff --git a/playbooks/roles/cleanup/tasks/cleanup.yml b/playbooks/roles/cleanup/tasks/cleanup.yml index 86f92a7d..39ba0b3b 100644 --- a/playbooks/roles/cleanup/tasks/cleanup.yml +++ b/playbooks/roles/cleanup/tasks/cleanup.yml @@ -1,25 +1,4 @@ --- -# Stop minishift profile, delete minishift profile, -# delete minishift binary files, and kube config - -- name: "Stop minishift if running" - shell: "{{ minishift_bin }} stop --profile {{ profile }}" - ignore_errors: yes - -- name: "Delete minishift profile {{ profile }}" - shell: "{{ minishift_bin }} delete --profile {{ profile }} --force" - ignore_errors: yes - -- name: "Cleanup files and directories {{ minishift_dest_dir }}" - file: - path: "{{ minishift_dest_dir }}/{{ item }}" - state: absent - with_items: - - "minishift" - - "LICENSE" - - "README.adoc" - ignore_errors: yes - - name: "Cleanup certain files in {{ contra_env_setup_dir }}, kube config, and minishift profile" file: path: "{{ item }}" @@ -27,8 +6,6 @@ with_items: - "{{ contra_env_setup_dir }}/.yml" - "{{ contra_env_setup_dir }}/.yaml" - - "{{ ansible_env.HOME }}/.minishift/profiles/{{ profile }}" - - "{{ ansible_env.HOME }}/.kube" ignore_errors: yes # Determine if project directory exists @@ -46,4 +23,4 @@ - "{{ contra_env_setup_dir }}/{{ project_dir }}" when: - pd_is_found.stat.exists - - force_repo_clone|bool == true \ No newline at end of file + - force_repo_clone|bool == true diff --git a/playbooks/roles/k8s_objects/tasks/main.yml b/playbooks/roles/k8s_objects/tasks/main.yml deleted file mode 100644 index 9bee4750..00000000 --- a/playbooks/roles/k8s_objects/tasks/main.yml +++ /dev/null @@ -1,52 +0,0 @@ ---- -- name: set minishift host - block: - - name: register minishift host - shell: "{{ minishift_bin }} ip" - register: minishift_host - - - name: set k8s_auth_host - set_fact: - k8s_auth_host: "https://{{ minishift_host.stdout }}:8443" - when: k8s_auth_host is not defined - -- name: set auth api key if env var is set - set_fact: - k8s_auth_api_key: "{{ ansible_env.K8S_AUTH_API_KEY }}" - when: ansible_env.K8S_AUTH_API_KEY is defined - -- name: Log in (obtain access token) - k8s_auth: - host: "{{ k8s_auth_host }}" - validate_certs: False - username: "{{ k8s_username }}" - password: "{{ k8s_password }}" - register: k8s_auth_results - when: k8s_username is defined and k8s_password is defined - -- name: set auth api key if username/password is provided - set_fact: - k8s_auth_api_key: "{{ k8s_auth_results.k8s_auth.api_key }}" - when: k8s_auth_results.k8s_auth.api_key is defined - -- name: Create openshift project - k8s: - host: "{{ k8s_auth_host }}" - api_key: "{{ k8s_auth_api_key }}" - name: "{{ PROJECT }}" - api_version: v1 - kind: Project - state: present - validate_certs: false - -- name: Creating k8s objects - k8s: - host: "{{ k8s_auth_host }}" - api_key: "{{ k8s_auth_api_key }}" - namespace: "{{ PROJECT }}" - state: present - validate_certs: false - definition: "{{ lookup('template', project_dir + '/' + os_template_dir + '/' + item) }}" - with_list: - "{{ k8s_resource_objects }}" - diff --git a/playbooks/roles/minishift/tasks/init_minishift.yml b/playbooks/roles/minishift/tasks/init_minishift.yml deleted file mode 100644 index 819240db..00000000 --- a/playbooks/roles/minishift/tasks/init_minishift.yml +++ /dev/null @@ -1,51 +0,0 @@ ---- -# start minishift -- name: "Initialization of minishift cluster with profile {{ profile }}" - shell: "{{ minishift_bin }} start --profile {{ profile }} --cpus {{ cpus }} --disk-size {{ disk_size }} --memory {{ memory }} --openshift-version {{ oc_version }} --iso-url file:///{{ minishift_dest_dir }}/minishift.iso" - -- block: - - name: "Check if is already set" - find: - paths: "/etc/libvirt/qemu" - patterns: "{{ profile }}.xml" - contains: '\s*' - register: minishift_vm_config_files - become: yes - - - set_fact: - cpu_mode_not_configured: ((minishift_vm_config_files | default([])) | length == 0) - - - name: "Wait for the cluster to come up completely" - pause: - minutes: 3 - when: (cpu_mode_not_configured|bool) or - (start_minishift|bool == false) - - - name: "Stop the minishift profile {{ profile }}" - shell: "{{ minishift_bin }} stop --profile {{ profile }}" - when: (cpu_mode_not_configured|bool) or - (start_minishift|bool == false) - - - name: "Update the minishift VM config" - lineinfile: - path: "/etc/libvirt/qemu/{{ profile }}.xml" - insertafter: '\s+' - line: " " - become: yes - when: cpu_mode_not_configured|bool - - - name: "Start minishift profile {{ profile }} again if configured" - shell: "{{ minishift_bin }} start --profile {{ profile }} --cpus {{ cpus }} --disk-size {{ disk_size }} --memory {{ memory }} --openshift-version {{ oc_version }} --iso-url file:///{{ minishift_dest_dir }}/minishift.iso" - when: - - cpu_mode_not_configured|bool - - start_minishift|bool == true - - - name: set minishift host - shell: "{{ minishift_bin }} ip" - register: minishift_host - - - name: set k8s_auth_host - set_fact: - k8s_auth_host: "https://{{ minishift_host.stdout }}:8443" - - when: host_os == "linux" diff --git a/playbooks/roles/minishift/tasks/install_minishift_bin.yml b/playbooks/roles/minishift/tasks/install_minishift_bin.yml deleted file mode 100644 index 06db132a..00000000 --- a/playbooks/roles/minishift/tasks/install_minishift_bin.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -# Install minishift - -- name: Query for minishift compressed binary - shell: curl -s https://github.com/minishift/minishift/releases/{{ minishift_version }} | grep 'minishift-.*-{{ host_os }}.*' | head -1 | sed 's/.*= 30 - become: true - -- name: Check if EPEL is installed for non Fedora distros - shell: rpm -qa | grep epel-release - register: epel_rpm - ignore_errors: yes - when: not ansible_distribution == 'Fedora' - become: true - -- name: Pull down the EPEL for for non Fedora distros - get_url: - url: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm" - dest: "{{ ansible_env.HOME }}/epel-release-latest-7.noarch.rpm" - when: - - not ansible_distribution == 'Fedora' - - epel_rpm.stdout == "" - -- name: Install EPEL for non Fedora distros - yum: - name: "{{ ansible_env.HOME }}/epel-release-latest-7.noarch.rpm" - state: present - when: - - not ansible_distribution == 'Fedora' - - epel_rpm.stdout == "" - become: true - -- name: "Install libvirt, qemu-kvm, and jq on {{ ansible_distribution }}" - package: - name: "{{ item }}" - state: present - with_items: - - libvirt - - qemu-kvm - - jq - - libselinux-python - - git - become: true - when: not ansible_distribution == 'Fedora' - -- name: "Install libvirt, qemu-kvm, and jq on {{ ansible_distribution }} version 29 or below" - package: - name: "{{ item }}" - state: present - with_items: - - libvirt - - qemu-kvm - - jq - - libselinux-python - - git - become: true - when: ansible_distribution == 'Fedora' and ansible_distribution_major_version|int <= 29 - -- name: "Install libvirt, qemu-kvm, and jq on {{ ansible_distribution }} version 30 or above" - package: - name: "{{ item }}" - state: present - with_items: - - libvirt - - qemu-kvm - - jq - - python3-libselinux - - git - become: true - when: ansible_distribution == 'Fedora' and ansible_distribution_major_version|int >= 30 diff --git a/playbooks/roles/prereqs/tasks/main.yml b/playbooks/roles/prereqs/tasks/main.yml deleted file mode 100644 index a8090322..00000000 --- a/playbooks/roles/prereqs/tasks/main.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -# tasks file for prereqs - -# install necessary virtualization plugins -- name: Linux pre reqs setup - block: - - import_tasks: setup_nested_virt.yml - when: setup_nested_virt|bool == true - - import_tasks: install_virtual_reqs.yml - - import_tasks: install_kvm_plugin.yml - when: host_os == "linux" - -# install homebrew and brew packages -- name: Mac pre req setup - import_tasks: install_mac_pre_reqs.yml - when: host_os == "darwin" diff --git a/playbooks/roles/prereqs/tasks/setup_nested_virt.yml b/playbooks/roles/prereqs/tasks/setup_nested_virt.yml deleted file mode 100644 index 7e4f48aa..00000000 --- a/playbooks/roles/prereqs/tasks/setup_nested_virt.yml +++ /dev/null @@ -1,78 +0,0 @@ ---- -# Check and enable virtualization if necessary -# REBOOT WILL BE REQUIRED IF ENABLED - -- name: "Check virtualization settings" - shell: cat /proc/cpuinfo | grep 'vmx\|svm' - register: cpuinfo - ignore_errors: true - when: run_prereqs|bool == true - -- name: "Output of cpuinfo from proc" - debug: - msg: "cpuinfo: {{ cpuinfo.stdout }}" - -- name: "Exit if virtualization is not turned on in the BIOS" - fail: msg="Please enable Intel virtualization (VT) or AMD (V) within the host machine's BIOS" - when: "cpuinfo.stdout == ''" - -- name: "Check virtualization settings for Intel" - command: cat /sys/module/kvm_intel/parameters/nested - register: nestedintel - ignore_errors: true - when: run_prereqs|bool == true - -- name: "Output of kvm_intel nested" - debug: - msg: "cpuinfo: {{ nestedintel.stdout }}" - when: "nestedintel.stdout != 'Y'" - -- name: "Setup nested virtualization Intel - rmmod" - command: rmmod kvm-intel - become: true - when: "nestedintel.stdout == 'N'" - -- name: "Setup nested virtualization Intel - update dist.conf" - shell: echo 'options kvm-intel nested=y' >> /etc/modprobe.d/dist.conf - become: true - when: "nestedintel.stdout == 'N'" - -- name: "Setup nested virtualization Intel - modprobe" - command: modprobe kvm-intel - become: true - when: "nestedintel.stdout == 'N'" - -- name: "Check virtualization settings for AMD" - command: cat /sys/module/kvm_amd/parameters/nested - register: nestedamd - ignore_errors: true - when: run_prereqs|bool == true - -- name: "Output of kvm_amd nested" - debug: - msg: "cpuinfo: {{ nestedamd.stdout }}" - when: "nestedamd.stdout == 'Y'" - -- name: "Setup nested virtualization AMD - rmmod" - command: rmmod kvm_amd - become: true - when: "nestedamd.stdout == 'N'" - -- name: "Setup nested virtualization AMD - update dist.conf" - shell: echo 'options kvm_amd nested=y' >> /etc/modprobe.d/dist.conf - become: true - when: "nestedamd.stdout == 'N'" - -- name: "Setup nested virtualization AMD - modprobe" - command: modprobe kvm_amd - become: true - when: "nestedamd.stdout == 'N'" - -- name: "Exit if nested virtualization is off" - fail: msg="NESTED VIRT HAS BEEN ENABLED PLEASE REBOOT" - when: - - nestedintel.stdout == "N" - - nestedamd.stdout == "N" - - - diff --git a/playbooks/setup.yml b/playbooks/setup.yml index f539bd23..a0cc0c44 100644 --- a/playbooks/setup.yml +++ b/playbooks/setup.yml @@ -16,7 +16,7 @@ - role: create - { role: prereqs, when: "run_prereqs|bool == true and setup_minishift|bool == true" } - { role: minishift, when: "setup_minishift|bool == true" } - - { role: k8s_objects, when: "set_containers|bool == true" } + - { role: os_temps, when: "set_containers|bool == true" } - { role: pipeline, when: setup_pipelines|bool == true } - { role: playbook_hooks, when: setup_playbook_hooks|bool == true } post_tasks: diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 00000000..24d2159c --- /dev/null +++ b/requirements.yml @@ -0,0 +1,11 @@ +# from GitHub, overriding the name and specifying a specific tag +- name: contra.minishift + src: git@github.com:CentOS-PaaS-SIG/contra-minishift.git + scm: git + version: master + +- name: contra.k8s_objects + src: git@github.com:CentOS-PaaS-SIG/contra-k8s_objects.git + scm: git + version: master +