diff --git a/playbooks/group_vars/all/global.yml b/playbooks/group_vars/all/global.yml index ec65a7c2..5201f34c 100644 --- a/playbooks/group_vars/all/global.yml +++ b/playbooks/group_vars/all/global.yml @@ -103,6 +103,16 @@ PARAMS: - key: REPO_REF val: "{{ project_branch }}" +# These are parameters that are passed to setup the helper containers in sample_project_repo +SAMPLE_HELPER_PARAMS: + - key: REPO_URL + val: "{{ sample_project_repo }}" + - key: REPO_REF + val: "{{ sample_project_branch }}" + +# These are parameters that are passed to setup the Jenkins master/slave containers in sample_project_repo +SAMPLE_JENKINS_PARAMS: "{{ SAMPLE_HELPER_CONTAINERS }}" + # These are parameters that are passed to setup the containers from the sample_project_repo SAMPLE_PARAMS: - key: REPO_URL diff --git a/playbooks/roles/os_temps/tasks/get_set_project.yml b/playbooks/roles/os_temps/tasks/get_set_project.yml index 511fe983..39e0c1ea 100644 --- a/playbooks/roles/os_temps/tasks/get_set_project.yml +++ b/playbooks/roles/os_temps/tasks/get_set_project.yml @@ -11,8 +11,4 @@ when: project_query.stdout == "" - name: add-role-to-user - shell: "{{ oc_bin }} policy add-role-to-user edit -z default -n '{{ openshift_project }}'" - - - - + shell: "{{ oc_bin }} policy add-role-to-user edit -z default -n '{{ openshift_project }}'" \ No newline at end of file diff --git a/playbooks/roles/os_temps/tasks/main.yml b/playbooks/roles/os_temps/tasks/main.yml index f12444a8..4af9e927 100644 --- a/playbooks/roles/os_temps/tasks/main.yml +++ b/playbooks/roles/os_temps/tasks/main.yml @@ -13,7 +13,7 @@ # Get ip of the cluster unless it was provided - name: "Get the cluster Server URL for project {{ openshift_project }}" - shell: "{{ oc_bin }} status | egrep '{{ openshift_project }}.*server' | awk '{print $NF}'" + shell: "{{ oc_bin }} status | grep 'https' | awk '{print $NF}' | head -1" register: cluster_ip_register when: openshift_cluster_ip == "" @@ -37,10 +37,28 @@ import_tasks: "{{ playbook_dir }}/roles/prereqs/tasks/install_virtual_reqs.yml" when: setup_minishift|bool == true -# setup_containers.yml -- import_tasks: setup_containers.yml +# Setup project_repo containers +- include_tasks: "setup_containers.yml os_template_path={{ project_dir }}/{{ os_template_dir }}" when: setup_containers|bool == true +# Setup sample_project_repo helper containers +- include_tasks: "setup_containers.yml os_template_path={{ helper_project_dir }}/{{ helper_os_template_dir }}/helper PARAMS={{ SAMPLE_HELPER_PARAMS }}" + when: (setup_containers|bool == true and project_repo != sample_project_repo) + +# Check if Jenkins is running +- name: "Check to see if a Jenkins Master instance is running" + shell: "{{ oc_bin }} get pods | grep -i 'running' | grep -i 'jenkins' | tail -1 | awk '{print $1}'" + register: jenkins_running + ignore_errors: yes + +# Setup sample_project_repo Jenkins master/slave sample containers +- include_tasks: "setup_containers.yml os_template_path={{ sample_project_dir }}/{{ sample_os_template_dir }}/jenkins PARAMS={{ SAMPLE_JENKINS_PARAMS }}" + when: (setup_containers|bool == true and project_repo != sample_project_repo and setup_sample_project|bool == true and jenkins_running.stdout == "") + +# Setup sample_project_repo sample containers +- include_tasks: "setup_containers.yml os_template_path={{ sample_project_dir }}/{{ sample_os_template_dir }}/samples PARAMS={{ SAMPLE_PARAMS }}" + when: (setup_containers|bool == true and project_repo != sample_project_repo and setup_sample_project|bool == true) + # Add security context constraints - import_tasks: add_scc.yml when: modify_scc|bool == true \ No newline at end of file diff --git a/playbooks/roles/os_temps/tasks/setup_containers.yml b/playbooks/roles/os_temps/tasks/setup_containers.yml index 1a7c231f..322894ce 100644 --- a/playbooks/roles/os_temps/tasks/setup_containers.yml +++ b/playbooks/roles/os_temps/tasks/setup_containers.yml @@ -6,80 +6,31 @@ container_config_name: "OpenShift s2i templates" # Use the repo's OpenShift s2i templates as the list to process -- name: "Get OpenShift s2i template names from {{ os_template_dir }}" +- name: "Get OpenShift s2i template names from {{ os_template_path }}" find: - paths: "{{ project_dir }}/{{ os_template_dir }}" + paths: "{{ os_template_path }}" patterns: '*.yml,*.yaml' recurse: yes register: os_templates -- name: "Get helper OpenShift s2i template names from {{ helper_os_template_dir }}/helper" - find: - paths: "{{ helper_project_dir }}/{{ helper_os_template_dir }}/helper" - patterns: '*.yml,*.yaml' - recurse: yes - register: helper_os_templates - when: project_repo != sample_project_repo - -- name: "Get sample OpenShift s2i template names from {{ sample_os_template_dir }}/samples" - find: - paths: "{{ sample_project_dir }}/{{ sample_os_template_dir }}/samples" - patterns: '*.yml,*.yaml' - recurse: yes - register: sample_os_templates - when: (project_repo != sample_project_repo and setup_sample_project|bool == true) - -# Check if Jenkins is running -- name: "Check to see if a Jenkins Master instance is running" - shell: "{{ oc_bin }} get pods | grep -i 'running' | grep -i 'jenkins' | tail -1 | awk '{print $1}'" - register: jenkins_running - ignore_errors: yes - -- name: "Get sample jenkins OpenShift s2i template names from {{ sample_os_template_dir }}/jenkins" - find: - paths: "{{ sample_project_dir }}/{{ sample_os_template_dir }}/jenkins" - patterns: '*.yml,*.yaml' - recurse: yes - register: sample_jenkins_os_templates - when: (project_repo != sample_project_repo and setup_sample_project|bool == true and jenkins_running.stdout == "") - -- set_fact: - all_templates: "{{ os_templates.files }}" - -- set_fact: - all_templates: "{{ os_templates.files }} + {{ helper_os_templates.files }}" - when: (project_repo != sample_project_repo and setup_sample_project|bool == false) - -- set_fact: - all_templates: "{{ os_templates.files }} + {{ sample_os_templates.files }} + {{ helper_os_templates.files }} " - when: (project_repo != sample_project_repo and setup_sample_project|bool == true) - - debug: msg: "{{ item.path }}" - with_items: "{{ all_templates }}" + with_items: "{{ os_templates.files }}" - name: "Process the templates" template: src: "{{ item.path }}" dest: "{{ item.path }}.processed" - with_items: "{{ all_templates }}" + with_items: "{{ os_templates.files }}" # Check that templates are valid - name: "Check that templates are valid" shell: "{{ oc_bin }} process -f {{ item.path }}.processed" - with_items: "{{ all_templates }}" + with_items: "{{ os_templates.files }}" # Load project_repo templates into OpenShift - include_tasks: "setup_os_templates.yml template_name={{ item.path }}.processed" with_items: "{{ os_templates.files }}" when: os_templates.files != "" -# Set PARAMS to the sample ones -- set_fact: - PARAMS: "{{ SAMPLE_PARAMS }}" - when: sample_os_templates.files is defined -# Load project_repo templates into OpenShift -- include_tasks: "setup_os_templates.yml template_name={{ item.path }}" - with_items: "{{ sample_os_templates.files }}" - when: (project_repo != sample_project_repo and setup_sample_project|bool == true)