Skip to content

Instantly share code, notes, and snippets.

@jbek7
Created April 18, 2020 23:29
Show Gist options
  • Save jbek7/2e35392cb396bb6d0a11de4be8f17d37 to your computer and use it in GitHub Desktop.
Save jbek7/2e35392cb396bb6d0a11de4be8f17d37 to your computer and use it in GitHub Desktop.
---
- name: "Log in to OKD"
k8s_auth:
host: "{{ okd_hostname }}"
username: "{{ lookup('hashi_vault', 'secret=secret/user-name:value') }}"
password: "{{ lookup('hashi_vault', 'secret=secret/user-password:value') }}"
register: k8s_auth_results
- name: "Set API key"
set_fact:
k8s_auth_host: "{{ okd_hostname }}"
k8s_auth_api_key: "{{ k8s_auth_results.k8s_auth.api_key }}"
- name: Apply k8s secret/config resources
k8s:
state: present
definition: "{{ lookup('template', '{{item}}.yml') }}"
host: "{{ k8s_auth_host }}"
api_key: "{{ k8s_auth_api_key }}"
loop:
- 01-secret
- 01-secret-tls
- 02-configmap
register: app_resources
- name: Apply k8s deployment resources
k8s:
state: present
definition: "{{ lookup('template', '{{item}}.yml') }}"
host: "{{ k8s_auth_host }}"
api_key: "{{ k8s_auth_api_key }}"
loop:
- 03-deployment
- 04-service
- 05-ingress
- name: Create kube config file
template:
src: "kube-config.yml"
dest: "/tmp/kube-config.yml"
when: app_resources.changed
- name: Rollout restart if configmap/secrets changed
shell: /bin/bash -c "kubectl rollout restart deployment my-deployment"
environment:
KUBECONFIG: "/tmp/kube-config.yml"
when: app_resources.changed
- name: Delete kube config file
file:
path: "/tmp/kube-config.yml"
state: absent
when: app_resources.changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment