Initial commit
[ta/infra-ansible.git] / conflicts-with-openstack-ansible / os-keystone-install.yml
1 ---
2 # Copyright 2014, Rackspace US, Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # cmframework.requires: memcached-install.yml,galera-install.yml,rabbitmq-install.yml,rsyslog-install.yml
16
17 - name: Prepare MQ/DB services
18   hosts: keystone_all
19   gather_facts: no
20   environment: "{{ deployment_environment_variables | default({}) }}"
21   tags:
22     - keystone
23   tasks:
24
25     - name: Configure rabbitmq vhost/user
26       include: common-tasks/rabbitmq-vhost-user.yml
27       vars:
28         user: "{{ keystone_rabbitmq_userid }}"
29         password: "{{ keystone_rabbitmq_password }}"
30         vhost: "{{ keystone_rabbitmq_vhost }}"
31         _rabbitmq_host_group: "{{ keystone_rabbitmq_host_group }}"
32       when:
33         - "groups[keystone_rabbitmq_host_group] | length > 0"
34       run_once: yes
35
36     - name: Configure rabbitmq vhost/user (telemetry)
37       include: common-tasks/rabbitmq-vhost-user.yml
38       vars:
39         user: "{{ keystone_rabbitmq_telemetry_userid }}"
40         password: "{{ keystone_rabbitmq_telemetry_password }}"
41         vhost: "{{ keystone_rabbitmq_telemetry_vhost }}"
42         _rabbitmq_host_group: "{{ keystone_rabbitmq_telemetry_host_group }}"
43       when:
44         - "keystone_ceilometer_enabled | bool"
45         - "groups[keystone_rabbitmq_telemetry_host_group] is defined"
46         - "groups[keystone_rabbitmq_telemetry_host_group] | length > 0"
47         - "groups[keystone_rabbitmq_telemetry_host_group] != groups[keystone_rabbitmq_host_group]"
48       run_once: yes
49
50     - name: Configure MySQL user
51       include: common-tasks/mysql-db-user.yml
52       vars:
53         user_name: "{{ keystone_galera_user }}"
54         password: "{{ keystone_container_mysql_password }}"
55         login_host: "{{ keystone_galera_address }}"
56         db_name: "{{ keystone_galera_database }}"
57       run_once: yes
58
59
60
61 - name: Installation and setup of Keystone
62   hosts: keystone_all
63   serial: "{{ keystone_serial | default(['1', '100%']) }}"
64   gather_facts: "{{ osa_gather_facts | default(True) }}"
65   environment: "{{ deployment_environment_variables | default({}) }}"
66   tags:
67     - keystone
68   pre_tasks:
69
70     # In order to ensure that any container, software or
71     # config file changes which causes a container/service
72     # restart do not cause an unexpected outage, we drain
73     # the load balancer back end for this container.
74     - include: common-tasks/haproxy-endpoint-manage.yml
75       vars:
76         haproxy_backend: "{{ item }}"
77         haproxy_state: disabled
78       when: "groups['keystone_all'] | length > 1"
79       with_items:
80         - "keystone_service-back"
81         - "keystone_admin-back"
82
83     - name: Configure container
84       include: "common-tasks/os-{{ container_tech | default('lxc') }}-container-setup.yml"
85       vars:
86         extra_container_config_no_restart:
87           - "lxc.start.order=19"
88
89     - name: Configure log directories (on metal)
90       include: common-tasks/os-log-dir-setup.yml
91       vars:
92         log_dirs:
93           - src: "/openstack/log/{{ inventory_hostname }}-keystone"
94             dest: "/var/log/keystone"
95
96     - include: common-tasks/unbound-clients.yml
97       static: no
98       when:
99         - hostvars['localhost']['resolvconf_enabled'] | bool
100
101     # todo(cloudnull): this task is being run only if/when keystone is installed on a physical host.
102     #  This is not being run within a container because it is an unsupported action due to this
103     #  issue: (https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1279041)
104     #  This issue was resolved however we'll need to eval it in the next LTS release.
105     #  Related OSA Bug: https://launchpad.net/bugs/1426371
106     - name: Add keystone reserved port to physical host
107       sysctl:
108         name: "{{ item.key }}"
109         value: "{{ item.value }}"
110         sysctl_set: "{{ item.set|default('yes') }}"
111         state: "{{ item.state|default('present') }}"
112         reload: "{{ item.reload|default('yes') }}"
113       with_items:
114         - { key: "net.ipv4.ip_local_reserved_ports", value: "{{ keystone_admin_port }}"}
115       when: is_metal | bool
116
117   roles:
118     - role: "os_keystone"
119       when: (reinitialized_nodes is not defined and scaled_out_nodes is not defined) or ((reinitialized_nodes is defined) and ((reinitialized_nodes | intersect(groups['keystone_all'])) | length > 0)) or (scaled_out_nodes is defined and hostname in scaled_out_nodes)
120     - role: "openstack_openrc"
121       tags:
122         - openrc
123     - role: "rsyslog_client"
124       rsyslog_client_log_rotate_file: keystone_log_rotate
125       rsyslog_client_log_dir: "/var/log/keystone"
126       rsyslog_client_config_name: "99-keystone-rsyslog-client.conf"
127       tags:
128         - rsyslog
129     - role: "system_crontab_coordination"
130       tags:
131         - crontab
132
133   post_tasks:
134     # Now that container changes are done, we can set
135     # the load balancer back end for this container
136     # to available again.
137     - include: common-tasks/haproxy-endpoint-manage.yml
138       vars:
139         haproxy_backend: "{{ item }}"
140         haproxy_state: enabled
141       when: "groups['keystone_all'] | length > 1"
142       with_items:
143         - "keystone_service-back"
144         - "keystone_admin-back"
145
146 # These facts are set against the deployment host to ensure that
147 # they are fast to access. This is done in preference to setting
148 # them against each target as the hostvars extraction will take
149 # a long time if executed against a large inventory.
150 - name: Finalise data migrations if required
151   hosts: keystone_all
152   gather_facts: no
153   environment: "{{ deployment_environment_variables | default({}) }}"
154   tags:
155     - keystone
156   tasks:
157     - name: refresh local facts
158       setup:
159         filter: ansible_local
160         gather_subset: "!all"
161
162     # This variable contains the values of the local fact set for the keystone
163     # venv tag for all hosts in the 'keystone_all' host group.
164     - name: Gather software version list
165       set_fact:
166         keystone_all_software_versions: "{{ (groups['keystone_all'] | map('extract', hostvars, ['ansible_local', 'openstack_ansible', 'keystone', 'venv_tag'])) | list }}"
167       delegate_to: localhost
168       run_once: yes
169
170     # This variable outputs a boolean value which is True when
171     # keystone_all_software_versions contains a list of defined
172     # values. If they are not defined, it means that not all
173     # hosts have their software deployed yet.
174     - name: Set software deployed fact
175       set_fact:
176         keystone_all_software_deployed: "{{ (keystone_all_software_versions | select('defined')) | list == keystone_all_software_versions }}"
177       delegate_to: localhost
178       run_once: yes
179
180     # This variable outputs a boolean when all the values in
181     # keystone_all_software_versions are the same and the software
182     - name: Set software updated fact
183       set_fact:
184         keystone_all_software_updated: "{{ ((keystone_all_software_versions | unique) | length == 1) and (keystone_all_software_deployed | bool) }}"
185       delegate_to: localhost
186       run_once: yes
187
188     - name: Perform a Keystone DB sync contract
189       command: "{{ keystone_bin }}/keystone-manage db_sync --contract"
190       become: yes
191       become_user: "{{ keystone_system_user_name }}"
192       when:
193         - "keystone_all_software_updated | bool"
194         - "ansible_local['openstack_ansible']['keystone']['need_db_contract'] | bool"
195       register: dbsync_contract
196       run_once: yes
197
198     - name: Disable the need for any further db sync
199       ini_file:
200         dest: "/etc/ansible/facts.d/openstack_ansible.fact"
201         section: keystone
202         option: "need_db_contract"
203         value: False
204       when:
205         - "dbsync_contract | succeeded"