diff --git a/adhoc-openshift-resources.yaml b/adhoc-openshift-resources.yaml new file mode 100644 index 0000000..f173575 --- /dev/null +++ b/adhoc-openshift-resources.yaml @@ -0,0 +1,29 @@ +# This playbook is to use templates/openshift-resources.j2 and extra vars +# (project details) and apply the resources created from the template. +# ansible-playbook playbooks/adhoc-openshift-resources.yaml -e "host=ocp-ci-management" -e "@projects_vars.yaml" +# +# Example of project_vars.yaml +# ``` +# project_name: billionDollarProject +# project_admins: +# - admin1 +# - admin2 +# +# bug_id: '000000' #bug id is the place/id where the project is requested +# ``` + + +- hosts: "{{ host }}" + become: true + become_user: "{{ ocp_service_account }}" + + tasks: + # generate the template for project to be created + - name: apply the template + template: + src: openshift-resources.j2 + dest: "/home/{{ ocp_service_account }}/ocp_configs/{{ project_name }}.yaml" + + # apply created openshift resources + - name: oc apply resources + command: "/home/{{ ocp_service_account }}/bin/oc apply -f /home/{{ ocp_service_account }}/ocp_configs/{{ project_name }}.yaml" diff --git a/templates/openshift-resources.j2 b/templates/openshift-resources.j2 new file mode 100644 index 0000000..ab18de6 --- /dev/null +++ b/templates/openshift-resources.j2 @@ -0,0 +1,34 @@ +--- +kind: Namespace +apiVersion: v1 +metadata: + name: "{{project_name}}" + annotations: + openshift.io/description: "{{ project_name }}" + openshift.io/display-name: "{{ project_name }}" + openshift.io/requester: siddharthvipul1@gmail.com + labels: + bug-id: "{{bug_id}}" +--- +kind: Group +apiVersion: user.openshift.io/v1 +metadata: + name: "{{project_name}}-admins" +users: +{% for item in project_members %} +- "{{ item }}" +{% endfor %} +--- +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: "{{project_name}}-admins" + namespace: "{{project_name}}" +subjects: + - kind: Group + apiGroup: rbac.authorization.k8s.io + name: "{{project_name}}-admins" +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: admin