Initial commit
[ta/infra-ansible.git] / roles / access-management / tasks / basic.yaml
1 # Copyright 2019 Nokia
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 - name: Ensures AM Configuration dir exists
16   file:
17     dest: "{{ am_server_config_dir }}"
18     state: directory
19
20 - name: Ensures AM temp dir exists
21   file:
22     dest: "{{ am_server_temp_dir }}"
23     state: directory
24   tags:
25     - am_dbfiller
26     - am_rc
27
28 - name: Ensures AM values dir exists
29   file:
30     dest: "{{ am_server_values_dir }}"
31     state: directory
32   tags:
33     - am_dbfiller
34
35 - name: AM backend log file creation and rights set
36   file:
37     path: "{{ am_config.Logging.logdir }}/am.log"
38     owner: access-manager
39     group: access-manager
40     mode: 0600
41     state: touch
42
43 - name: Patch log file creation and rights set
44   file:
45     path: "{{ am_config.Logging.logdir }}/keystone_users_patch.log"
46     owner: access-manager
47     group: access-manager
48     mode: 0600
49     state: touch
50
51 - name: Create AM Plugin Config
52   template:
53     src: am.plugin.conf.j2
54     dest: "{{ am_plugin_config_path }}"
55     owner: restapi
56     group: restapi
57     mode: 0400
58
59 - name: Create AM Backend Config
60   template:
61     src: am.backend.conf.j2
62     dest: "{{ am_backend_config_path }}"
63     owner: access-manager
64     group: access-manager
65     mode: 0400
66
67 - name: Ensure project for um_admin exists
68   run_once: true
69   keystone:
70     command: ensure_project
71     project_name: "{{ am_project_name }}"
72     domain_name: "{{ am_project_domain }}"
73     login_user: "{{ keystone_admin_user_name }}"
74     login_password: "{{ keystone_auth_admin_password }}"
75     login_project_name: "{{ keystone_admin_tenant_name }}"
76     endpoint: "{{ keystone_service_adminurl }}"
77     insecure: "{{ keystone_service_adminuri_insecure }}"
78
79 - name: Ensure um_admin user
80   run_once: true
81   keystone:
82     command: "ensure_user"
83     endpoint: "{{ keystone_service_adminurl }}"
84     login_user: "{{ keystone_admin_user_name }}"
85     login_password: "{{ keystone_auth_admin_password }}"
86     login_project_name: "{{ keystone_admin_tenant_name }}"
87     user_name: "{{ infrastructure_admin_user_name }}"
88     tenant_name: "{{ am_project_name }}"
89     password: "{{ infrastructure_admin_password }}"
90     insecure: "{{ keystone_service_adminuri_insecure }}"
91   register: um_admin_uuid
92   until: um_admin_uuid|success
93   retries: 5
94   delay: 10
95
96 - name: Ensure UM admin user added to admin role
97   run_once: true
98   keystone:
99     command: "ensure_user_role"
100     endpoint: "{{ keystone_service_adminurl }}"
101     login_user: "{{ keystone_admin_user_name }}"
102     login_password: "{{ keystone_auth_admin_password }}"
103     login_project_name: "{{ keystone_admin_tenant_name }}"
104     user_name: "{{ infrastructure_admin_user_name }}"
105     tenant_name: "{{ am_project_name }}"
106     role_name: "{{ am_admin_role_name }}"
107     insecure: "{{ keystone_service_adminuri_insecure }}"
108   register: add_service
109   until: add_service|success
110   retries: 5
111   delay: 10
112
113 - name: Ensure keystone admin user added to member role
114   run_once: true
115   keystone:
116     command: "ensure_user_role"
117     endpoint: "{{ keystone_service_adminurl }}"
118     login_user: "{{ keystone_admin_user_name }}"
119     login_password: "{{ keystone_auth_admin_password }}"
120     login_project_name: "{{ keystone_admin_tenant_name }}"
121     user_name: "{{ keystone_admin_user_name }}"
122     tenant_name: "{{ am_project_name }}"
123     role_name: "{{ am_member_role_name }}"
124     insecure: "{{ keystone_service_adminuri_insecure }}"
125   register: add_service
126   until: add_service|success
127   retries: 5
128   delay: 10
129
130 - name: Set default project for keystone admin user
131   run_once: true
132   command: openstack user set {{ keystone_admin_user_name }} --project {{ am_project_name }} --os-cloud default
133
134 - name: Add the security_compliance section to keystone.conf
135   ini_file:
136     path: /etc/keystone/keystone.conf
137     section: security_compliance
138     option: "{{ item.option }}"
139     value: "{{ item.value }}"
140   with_items:
141     - { option: "lockout_failure_attempts", value: "{{ host_os.failed_login_attempts | default(5) }}" }
142     - { option: "lockout_duration", value: "{{ host_os.lockout_time | default(300) }}" }
143     - { option: "change_password_upon_first_use", value: "True" }
144     - { option: "password_expires_days", value: "90" }
145     - { option: "unique_last_password_count", value: "12" }
146     - { option: "minimum_password_age", value: "0" }
147     - { option: "password_regex", value: "^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[][.,:;/(){}<>~\\!?@#$%^&*_=+-])[][a-zA-Z0-9.,:;/(){}<>~\\!?@#$%^&*_=+-]{8,255}$" }
148     - { option: "password_regex_description", value: "The password must have a minimum length of 8 characters (maximum is 255 characters). The allowed characters are lower case letters (a-z), upper case letters (A-Z), digits (0-9), and special characters (.,:;/(){}<>~\\!?@#$%^&*_=+-). The password must contain at least one upper case letter, one digit and one special character." }
149
150 - name: Restart Keystone WSGI services
151   service:
152     name: "{{ item }}"
153     enabled: yes
154     state: "restarted"
155     daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
156   register: _start1
157   until: _start1 | success
158   retries: 5
159   delay: 3
160   with_items:
161     - keystone-wsgi-public
162     - keystone-wsgi-admin
163
164 - name: Wait for Keystone WSGI services to restart
165   wait_for:
166     port: "{{ item }}"
167     host: "{{ extra_hosts_entries.haproxyvip }}"
168     timeout: 25
169     delay: 10
170   with_items:
171     - "{{ keystone_service_port }}"
172     - "{{ keystone_admin_port }}"
173   register: _wait_check1
174   until: _wait_check1 | success
175   retries: 5
176
177 - name:  Wait for Keystone WSGI services to respond
178   shell: openstack user list --os-cloud default
179   register: result
180   until: result | success
181   delay: 2
182   retries: 5
183
184 - name: Create OpenStack client configuration directory
185   file:
186     dest: "{{ openrc_openstack_client_config_dir_dest }}"
187     owner: "{{ openrc_openstack_client_config_dir_owner }}"
188     group: "{{ openrc_openstack_client_config_dir_group }}"
189     state: directory
190
191 - name: Change authorization in YARF config
192   lineinfile:
193     path: "/etc/yarf/config.ini"
194     regexp: "auth_method=.*"
195     line: "auth_method=access_management.backend.am_auth.AMAuth"
196
197 - name: Restart YARF service
198   service:
199     name: restapi
200     enabled: yes
201     state: "restarted"
202     daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
203   register: _start2
204   until: _start2 | success
205   retries: 5
206   delay: 3
207
208 - name: Wait for YARF service to restart
209   wait_for:
210     port: "{{ restful_service_port }}"
211     host: "{{ extra_hosts_entries.haproxyvip }}"
212     timeout: 25
213     delay: 10
214   register: _wait_check2
215   until: _wait_check2 | success
216   retries: 5