Skip to content

Commit

Permalink
Merge pull request #49 from arilivigni/master
Browse files Browse the repository at this point in the history
 Rework importing of os templates
  • Loading branch information
arilivigni authored Jun 6, 2018
2 parents 7c407e0 + 5c74fcf commit f34baca
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 62 deletions.
10 changes: 10 additions & 0 deletions playbooks/group_vars/all/global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions playbooks/roles/os_temps/tasks/get_set_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'"
24 changes: 21 additions & 3 deletions playbooks/roles/os_temps/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ""

Expand All @@ -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
59 changes: 5 additions & 54 deletions playbooks/roles/os_temps/tasks/setup_containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f34baca

Please sign in to comment.