Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NAMESPACE=my-project1
NAMESPACE_DISPLAY_NAME=My Example Project 1
NAMESPACE_DESCRIPTION=Example of creating a project in cluster 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NAMESPACE=your-project1
NAMESPACE_DISPLAY_NAME=Your Example Project 1
NAMESPACE_DESCRIPTION=Example of creating a project in cluster 2
17 changes: 17 additions & 0 deletions inventory/sample-multi-clusters.d/inventory/host_vars/cluster1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

ansible_connection: local

openshift_login_url: https://console.cluster1.example.com
openshift_token: R45tdflgkj123asdf_sdfit
# openshift_insecure: true


openshift_cluster_content:
- object: projects
content:
- name: "my project 1"
template: https://raw.githubusercontent.com/redhat-cop/cluster-lifecycle/master/files/projectrequest/template.yml
params: "{{ inventory_dir }}/../files/cluster1/projects/my-project1.param"
template_action: create

15 changes: 15 additions & 0 deletions inventory/sample-multi-clusters.d/inventory/host_vars/cluster2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

ansible_connection: local

openshift_login_url: https://console.cluster2.example.com
openshift_token: ssdflsdkf34l5jk34l5kjvdf
# openshift_insecure: true

openshift_cluster_content:
- object: projects
content:
- name: "your project 1"
template: https://raw.githubusercontent.com/redhat-cop/cluster-lifecycle/master/files/projectrequest/template.yml
params: "{{ inventory_dir }}/../files/cluster2/projects/your-project1.param"
template_action: create
6 changes: 6 additions & 0 deletions inventory/sample-multi-clusters.d/inventory/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


[seed-hosts]
cluster1
cluster2

2 changes: 1 addition & 1 deletion playbooks/openshift-cluster-seed.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
- hosts: seed-hosts[0]
- hosts: seed-hosts
roles:
- openshift-applier
Binary file not shown.
4 changes: 4 additions & 0 deletions roles/openshift-applier/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
with_items:
- "{{ tmp_dep_dir }}"

- name: "Cleanup OpenShift config"
file:
path: "{{ openshift_config_tempdir.path }}"
state: absent
3 changes: 3 additions & 0 deletions roles/openshift-applier/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
when:
- ansible_connection != 'local'

- name: "Prep Access to OpenShift environment(s)"
import_tasks: prep-access.yml

- name: "Create OpenShift objects"
include_tasks: process-content.yml
with_items:
Expand Down
19 changes: 19 additions & 0 deletions roles/openshift-applier/tasks/prep-access.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---

- name: "Create temporary dir"
tempfile:
state: directory
prefix: "openshift-{{ ansible_host }}"
register: openshift_config_tempdir
notify:
- "Cleanup OpenShift config"

- name: "Define temporary config dir"
set_fact:
kubeconfig: "{{ openshift_config_tempdir.path }}/config"

- name: "Capture OpenShift Config based on token"
command: >
oc login --token={{ openshift_token }} {{ openshift_insecure | ternary('--insecure-skip-tls-verify', '') }} {{ openshift_login_url }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause pre-existing applier inventories to fail if not set. I would suggest two things:

  • first, make this optional. i.e. skip it if these variables are not set
  • set a default value for openshift_insecure so that it is not required.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etsauer yes, there are multiple things that need to be polished before this can be merged. Main intent for the PR was to have a discussion starting point around the concept (and if it's worth spending time on it)

environment:
KUBECONFIG: "{{ kubeconfig }}"
2 changes: 2 additions & 0 deletions roles/openshift-applier/tasks/process-content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
ignore_errors: true
- command: >
oc apply -f {{ tmp_inv_dir }}{{ entry.content_dir }}
environment:
KUBECONFIG: "{{ kubeconfig }}"
when:
- entry.content_dir is defined
- entry.content_dir|trim != ''
Expand Down
6 changes: 6 additions & 0 deletions roles/openshift-applier/tasks/process-one-entry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
- name: "{{ file_action | capitalize }} OpenShift objects based on static files for '{{ entry.object}} : {{ content.name | default(file | basename) }}'"
command: >
oc {{ file_action }} {{ target_namespace }} -f {{ file }} {{ (file_action == 'delete') | ternary(' --ignore-not-found', '') }}
environment:
KUBECONFIG: "{{ kubeconfig }}"
register: command_result
failed_when:
- command_result.rc != 0
Expand All @@ -101,6 +103,8 @@
{{ target_namespace }} \
--param-file={{ tmp_inv_dir }}{{ content.params }} | \
oc {{ template_action }} {{ target_namespace }} -f - {{ (template_action == 'delete') | ternary(' --ignore-not-found', '') }}
environment:
KUBECONFIG: "{{ kubeconfig }}"
register: command_result
failed_when:
- command_result.rc != 0
Expand All @@ -118,6 +122,8 @@
{{ target_namespace }} \
--param-file={{ item }} | \
oc {{ template_action }} {{ target_namespace }} -f - {{ (template_action == 'delete') | ternary(' --ignore-not-found', '') }}
environment:
KUBECONFIG: "{{ kubeconfig }}"
register: command_result
failed_when:
- command_result.rc != 0
Expand Down