Execution
Date 08 Dec 2025 13:39:52 +0000
Duration 00:35:02.03
Controller aio1.openstack.local
User root
Versions
Ansible 2.18.6
ara 1.7.4 / 1.7.4
Python 3.12.3
Summary
2 Hosts
1377 Tasks
1365 Results
104 Plays
504 Files
0 Records

File: /home/zuul/src/opendev.org/openstack/openstack-ansible-os_keystone/tasks/keystone_fernet_keys_create.yml

---
# Copyright 2015, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: Check if fernet keys already exist
  ansible.builtin.stat:
    path: "{{ keystone_fernet_tokens_key_repository }}/0"
  register: _fernet_keys

- name: Check for fernet keys on all Keystone containers
  ansible.builtin.find:
    paths: "{{ keystone_fernet_tokens_key_repository }}"
  when: not _fernet_keys.stat.exists
  register: _fernet_key_list
  delegate_to: "{{ item }}"
  with_items: "{{ groups['keystone_all'] }}"

- name: Identify hosts with existing fernet keys
  ansible.builtin.set_fact:
    existing_fernet_hosts: >-
      {% set _var = [] -%}
      {% for result in _fernet_key_list.results -%}
      {%   if result.files is defined and (result.files | length) > 0 -%}
      {%       if _var.append(result.item) -%}{% endif -%}
      {%   endif -%}
      {% endfor -%}
      {{ _var }}
  when: not _fernet_key_list is skipped

- name: Copy the fernet key repository to the primary
  ansible.builtin.command: >
    rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
          -avz
          --delete
          {{ keystone_system_user_name }}@{{ existing_fernet_hosts[0] }}:{{ keystone_fernet_tokens_key_repository }}/
          {{ keystone_fernet_tokens_key_repository }}/
  become: true
  become_user: "{{ keystone_system_user_name }}"
  changed_when: false
  register: _fernet_keys_shared
  when:
    - existing_fernet_hosts is defined
    - (existing_fernet_hosts | length) > 0
  tags:
    - skip_ansible_lint

- name: Create fernet keys for Keystone # noqa: no-changed-when
  ansible.builtin.command: >
    {{ keystone_bin }}/keystone-manage fernet_setup
                                       --keystone-user "{{ keystone_system_user_name }}"
                                       --keystone-group "{{ keystone_system_group_name }}"
  become: true
  become_user: "{{ keystone_system_user_name }}"
  when:
    - not _fernet_keys.stat.exists
    - _fernet_keys_shared is skipped

- name: Rotate fernet keys for Keystone # noqa: no-changed-when
  ansible.builtin.command: >
    {{ keystone_bin }}/keystone-manage fernet_rotate
                                       --keystone-user "{{ keystone_system_user_name }}"
                                       --keystone-group "{{ keystone_system_group_name }}"
  become: true
  become_user: "{{ keystone_system_user_name }}"
  when: _fernet_keys.stat.exists