Skip to content

Instantly share code, notes, and snippets.

@nccurry
Last active October 6, 2017 15:34
Show Gist options
  • Save nccurry/39b8da2585ce9323a1f95e929e89c3e7 to your computer and use it in GitHub Desktop.
Save nccurry/39b8da2585ce9323a1f95e929e89c3e7 to your computer and use it in GitHub Desktop.
Insert htpasswd identity provider on all OpenShift master hosts
---
# ansible-playbook insert-htpasswd-identity-ocp.yaml --extra-vars '{"master_host_group":"masters","users":["user1","user2"],"password":"password"}'
- hosts: localhost
connection: local
become: false
tasks:
- name: Add users to htpasswd file
htpasswd:
create: yes
state: present
path: ./users.htpasswd
name: "{{ item }}"
password: "{{ password }}"
mode: 0640
with_items: "{{ users }}"
- hosts: "{{ master_host_group }}"
become: true
tasks:
- name: Copy htpasswd file to masters
copy:
src: users.htpasswd
dest: /etc/origin/master/users.htpasswd
- name: Add htpasswd identity provider stanza to master-config.yaml
blockinfile:
dest: /etc/origin/master/master-config.yaml
state: present
insertafter: 'identityProviders:'
block: |
workaround_line
- name: htpasswd
challenge: true
login: true
mappingMethod: claim
provider:
apiVersion: v1
kind: HTPasswdPasswordIdentityProvider
file: /etc/origin/master/users.htpasswd
- name: Removed block spacing workaround line
lineinfile:
dest: /etc/origin/master/master-config.yaml
regexp: ^workaround_line$
state: absent
changed_when: false
- name: Restart OpenShift Master API
systemd:
name: atomic-openshift-master-api.service
state: restarted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment