From 9a96e473f76df136113e8d47059b6f7e11964f8a Mon Sep 17 00:00:00 2001 From: kpavic Date: Fri, 22 Feb 2019 14:13:01 +0100 Subject: [PATCH] Add a playbook that prepares external VMs for usage with minishift --- README.md | 33 +++++++++++++++ playbooks/prepare_vm_for_minishift.yml | 58 ++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 playbooks/prepare_vm_for_minishift.yml diff --git a/README.md b/README.md index f86dfe75..a4c513da 100644 --- a/README.md +++ b/README.md @@ -473,6 +473,39 @@ _Note: The -K is used to prompt you for your password for sudo (if you require o Instead of -k you could use --private-key=_ +### Example 10: Setup on an existing generic virtual machine :: Setup Jenkins with metrics enabled + + 1. Prepare an existing generic centos7/fedora27+ VM with VM_IP as a USER with paswordless sudo privileges + 2. Install on an existing VM as a USER, enable nested virtualization + 3. Start minishift cluster with profile minishift + 4. Run Jenkins with metrics enabled + 5. Load containers from a user defined as project_repo from joejstuart/contra-demo + 6. Load helper containers from CentOS-PaaS-SIG/contra-env-infra + 7. Setup Jenkins with a a job DSL seed job and sample jobs from CentOS-PaaS-SIG/contra-env-sample-project + 8. Disable the linchpin-executor container + +``` +ansible-playbook -vv -i "VM_IP," -u USER contra-env-setup/playbooks/prepare_vm_for_minishift.yml \ + -e setup_nested_virt=true --private-key=PATH_TO_PRIVATE_KEY + +ansible-playbook -vv -i "localhost," contra-env-setup/playbooks/setup.yml \ + -e user=$USER \ + -e profile=minishift \ + -e minishift_external_vm_user=USER \ + -e minishift_external_vm_ssh_key_location=PATH_TO_PRIVATE_KEY \ + -e minishift_external_vm_ip=VM_IP \ + -e run_prereqs=false \ + -e setup_minishift=true \ + -e start_minishift=true \ + -e setup_containers=true \ + -e helper_project_repo=https://github.com/CentOS-PaaS-SIG/contra-env-infra \ + -e helper_project_branch=master \ + --extra-vars='{"os_template_blacklist": ["linchpin-executor", "ansible-executor"]}' \ + -e project_repo=https://github.com/joejstuart/contra-demo \ + -e project_branch=master \ + -e jenkins_enable_metrics=true \ + -e jenkins_dsl_job_repo=CentOS-PaaS-SIG/contra-env-sample-project -K -k +``` ## Mac Users diff --git a/playbooks/prepare_vm_for_minishift.yml b/playbooks/prepare_vm_for_minishift.yml new file mode 100644 index 00000000..1316d196 --- /dev/null +++ b/playbooks/prepare_vm_for_minishift.yml @@ -0,0 +1,58 @@ +- hosts: '{{ hosts | default("all") }}' + become: '{{ become | default("yes") }}' + gather_facts: '{{ gather_facts | default("no") }}' + + vars: + setup_nested_virt: false + + tasks: + - name: "Install python if not installed" + raw: test -e /usr/bin/python || sudo yum install -y python + + - name: "Install docker, net-tools and firewalld" + package: + name: "{{ item }}" + state: present + with_items: + - docker + - net-tools + - firewalld + + - name: "Ensure group docker exists" + group: + name: docker + state: present + + - name: "Adding existing user {{ ansible_user }} to group docker" + user: + name: "{{ ansible_user }}" + groups: docker + append: yes + + - name: "Ensure that docker service is running" + service: + name: docker + state: reloaded + enabled: yes + + - name: "Set run_prereqs to true for the virtualization setup" + set_fact: + run_prereqs: true + when: setup_nested_virt|bool == true + + - name: "Setup nested virtualization on the VM" + import_tasks: "{{ playbook_dir }}/roles/prereqs/tasks/setup_nested_virt.yml" + when: setup_nested_virt|bool == true + + - name: "Restart VM if nested virtualization was setup" + shell: sleep 2 && shutdown -r now "Restarting to finish nested virtualization setup" + async: 1 + poll: 0 + ignore_errors: true + when: setup_nested_virt|bool == true + + - name: "Wait for the VM to finish reboot" + wait_for_connection: + timeout: 240 + delay: 20 + when: setup_nested_virt|bool == true