Initial commit
[ta/infra-ansible.git] / roles / update_cert / tasks / main.yml
1 ---
2
3 # Copyright 2019 Nokia
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 - name: Set basic facts
18   set_fact:
19     deploy_pem: False
20     upload_pem: False
21     pem_location: ""
22   tags:
23     - runtime
24
25 - name: Check if custom pem installed during deploy
26   stat:
27     path: "/opt/installer-ui/certificates/certificate.pem"
28   register: stat_result_deploy
29   tags:
30    - runtime
31
32 - name: Set fact deploy_pem
33   set_fact:
34     deploy_pem: True
35     upload_pem: False
36     pem_location: "/opt/installer-ui/certificates/certificate.pem"
37   when: stat_result_deploy.stat.exists == True
38   tags:
39     - runtime
40
41 - name: Check if pem is uploaded
42   stat:
43     path: "/tmp/certificate.pem"
44   register: stat_result_uploaded
45   tags:
46     - runtime
47   when: deploy_pem == False
48
49 - name: Set fact upload_pem
50   set_fact:
51     upload_pem: True
52     deploy_pem: False
53     pem_location: "/tmp/certificate.pem"
54   when: stat_result_uploaded.stat.exists == True
55   tags:
56     - runtime
57
58 - name: Validate certificate
59   openssl_certificate:
60     path: "{{ pem_location }}"
61     provider: assertonly
62     has_expired: False
63   tags:
64     - runtime
65   when: upload_pem == True or deploy_pem == True
66
67 - name: Synchronize pem
68   synchronize:
69     src: "{{ pem_location }}"
70     dest: "/tmp/certificate.pem"
71   tags:
72     - runtime
73   become: yes
74   when: upload_pem == True or deploy_pem == True
75
76 - name: Copy pem
77   copy:
78     src: "/tmp/certificate.pem"
79     dest: "/etc/ssl/private/certificate.pem"
80   tags:
81     - runtime
82   when: upload_pem == True or deploy_pem == True
83
84 - name: Set permissions for pem
85   file:
86     path: "/etc/ssl/private/certificate.pem"
87     mode: '0440'
88     group: 'ironic'
89     owner: 'root'
90   tags:
91     - runtime
92   when: upload_pem == True or deploy_pem == True
93
94 - name: Restart haproxy
95   service:
96     name: "haproxy"
97     state: "restarted"
98     enabled: yes
99     daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
100   tags:
101     - runtime
102   when: upload_pem == True or deploy_pem == True