Razique Mahroua
2020-03-18 b85c91a8192593f6b62f93e11c971868964343a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
---
# Implement your Workload deployment tasks here
 
- name: Setting up workload for user
  debug:
    msg: "Setting up workload for user ocp_username = {{ ocp_username }}"
 
- include_role:
    name: idm-server
  vars:
    become_override: yes
 
# /home/{{ ansible_user }}/.aws/credentials needs to exist before calling this role
- name: Create Let's Encrypt Certificates
  include_role:
    name: host-lets-encrypt-certs-certbot
  vars:
  - _certbot_domain: "{{ idm_dns_name }}"
  - _certbot_wildcard_domain: "{{cluster_name}}{{subdomain_base_suffix}}"
  - _certbot_dns_provider: "route53"
  - _certbot_remote_dir: "/home/{{ ansible_user }}/idm"
  - _certbot_remote_dir_owner: "{{ ansible_user }}"
  - _certbot_install_dir: "/home/{{ ansible_user }}/idm/certificates"
  - _certbot_install_dir_owner: "{{ ansible_user }}"
  - _certbot_cache_archive_file: "{{ output_dir|d('/tmp') }}/{{ guid }}-idm-certs.tar.gz"
  - _certbot_renew_automatically: True
  - _certbot_use_cache: True
  - _certbot_force_issue: True
  - _certbot_production: True
  - _certbot_cron_job_name: LETS_ENCRYPT_RENEW_IDM
 
- name: Get Root CA
  copy:
    src: ./files/DSTRootCAX3.pem
    dest: /tmp/DSTRootCAX3.pem
 
- name: Get Intermediate CA
  copy:
    src: ./files/LEAuthX3.pem
    dest: /tmp/LEAuthX3.pem
 
- name: Install CAs
  shell: |
    echo '{{ idm_admin_password }}' | kinit admin
    ipa-cacert-manage -p '{{ idm_dm_password }}' install /tmp/DSTRootCAX3.pem -n DSTRootCAX3 -t C,,
    ipa-cacert-manage -p '{{ idm_dm_password }}' install /tmp/LEAuthX3.pem -n LEAuthX3 -t C,,
    ipa-certupdate -v
  become: True
 
- name: Install IPA Certificate
  shell: |
    ipa-server-certinstall -w -d /home/{{ ansible_user }}/idm/certificates/privkey.pem /home/{{ ansible_user }}/idm/certificates/fullchain.pem -p '{{ idm_dm_password }}' --pin=''
    ipactl restart
  become: True
 
- name: Install redeploy hook scripts
  template:
    src: ./files/deploy_certs.sh
    dest: "/home/{{ ansible_user }}/idm/certbot/config/renewal-hooks/deploy/deploy_certs.sh"
    mode: 0775
    owner: "{{ ansible_user }}"
- name: Install redeploy hook ansible components
  copy:
    src: "./files/{{ item }}"
    dest: "/home/{{ ansible_user }}/idm/certbot/config/renewal-hooks/deploy/{{ item }}"
    mode: 0664
    owner: "{{ ansible_user }}"
  loop:
  - deploy_certs.yml
 
- name: Install AWS python prerequisites
  become: True
  pip:
    state: present
    name:
    - boto
    - botocore
    - boto3
 
# Find public IP of bastion
- name: Gather VPC facts
  ec2_vpc_net_facts:
    filters:
      tag:Name: "{{ aws_vpc_name }}"
    region: "{{ aws_region_final | default(aws_region) }}"
  register: vpc
 
- name: Get instance facts
  ec2_instance_facts:
    filters:
# FIXME - find a better way to discover the bastion name
      "tag:Name": "{{ instances[0].name }}"
    region: "{{ aws_region_final | default(aws_region) }}"
  register: instancesr
  failed_when: instancesr|length == 0
 
- name: Get non-terminated instance
  set_fact:
    ec2instance: "{{ item }}"
  with_items:
  - "{{ instancesr.instances }}"
  when: not item.state.name == 'terminated'
  failed_when: ec2instance is undefined
 
# Make external DNS of IdM available to OpenShift cluster
- name: Get cluster metadata
  slurp:
    path: "{{ cluster_name }}/metadata.json"
  register: metadata
 
- name: Get cluster infrastructure ID
  set_fact:
    cluster_vpc_name: "{{ metadata.content | b64decode | from_json | json_query('infraID')}}-vpc"
 
- name: Gather Cluster VPC facts
  ec2_vpc_net_facts:
    filters:
      tag:Name: "{{ cluster_vpc_name }}"
    region: "{{ aws_region_final | default(aws_region) }}"
  register: cluster_vpc
  failed_when: cluster_vpc.vpcs | length == 0
 
- name: Create Private DNS Entry for IdM in cluster private zone
  route53:
    state: present
    overwrite: yes
    private_zone: yes
    record: "{{ idm_dns_name }}"
    type: A
    ttl: 60
    value: "{{ ec2instance.public_ip_address }}"
    zone: "{{ cluster_name }}{{ subdomain_base_suffix }}."
    vpc_id: "{{ cluster_vpc.vpcs[0].vpc_id }}"
 
- name: Configure Local Authentication
  when:
  - install_ocp4 | d(False) | bool
  - install_idm is defined
  environment:
    KUBECONFIG: "{{ cluster_name }}/auth/kubeconfig"
  block:
  - name: Set up Local IdM LDAP
    when:
    - install_idm == "local-ldap"
    block:
    - name: Create admin user
      when: admin_user is defined
      ipa_user:
        name: "{{ admin_user }}"
        password: "{{ admin_password }}"
        state: present
        givenname: OpenShift
        sn: Administrator
        mail:
        - "{{ email }}"
        ipa_host: "{{ idm_dns_name }}"
        ipa_user: admin
        ipa_pass: "{{ idm_admin_password }}"
    - name: Upload OAuth Configuration File
      template:
        src: "./files/oauth-ldap.yaml"
        dest: "/home/{{ ansible_user }}/oauth-ldap.yaml"
        owner: "{{ ansible_user }}"
        mode: 0664
    - name: Update OAuth Configuration
      shell: "oc apply -f /home/{{ ansible_user }}/oauth-ldap.yaml"
    - name: Remove kubeadmin User
      when:
      - admin_user is defined
      - auth_remove_kubeadmin
      command: oc delete secret kubeadmin -n kube-system
      ignore_errors: true
 
# Leave this as the last task in the playbook.
- name: workload tasks complete
  debug:
    msg: "Workload Tasks completed successfully."
  when: not silent|bool