|
| 1 | +--- |
| 2 | +# Copyright 2023 Red Hat, Inc. |
| 3 | +# All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. You may obtain |
| 7 | +# 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, WITHOUT |
| 13 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | +# License for the specific language governing permissions and limitations |
| 15 | +# under the License. |
| 16 | +- name: Gather user fact |
| 17 | + ansible.builtin.setup: |
| 18 | + gather_subset: |
| 19 | + - "!all" |
| 20 | + - "!min" |
| 21 | + - "user" |
| 22 | + when: |
| 23 | + - ansible_user is undefined |
| 24 | + |
| 25 | +- name: Ensure new config directory exists |
| 26 | + tags: |
| 27 | + - update |
| 28 | + - neutron_metadata |
| 29 | + become: true |
| 30 | + ansible.builtin.file: |
| 31 | + path: "{{ edpm_neutron_metadata_agent_config_dir }}" |
| 32 | + state: directory |
| 33 | + setype: "container_file_t" |
| 34 | + owner: "{{ ansible_user | default(ansible_user_id) }}" |
| 35 | + group: "{{ ansible_user | default(ansible_user_id) }}" |
| 36 | + |
| 37 | +- name: Check if old config directory exists |
| 38 | + tags: |
| 39 | + - update |
| 40 | + - neutron_metadata |
| 41 | + ansible.builtin.stat: |
| 42 | + path: "/var/lib/config-data/ansible-generated/neutron-ovn-metadata-agent" |
| 43 | + register: edpm_neutron_metadata_old_config_dir |
| 44 | + |
| 45 | +- name: Move config files from old location to new location |
| 46 | + tags: |
| 47 | + - update |
| 48 | + - neutron_metadata |
| 49 | + become: true |
| 50 | + when: |
| 51 | + - edpm_neutron_metadata_old_config_dir.stat.exists |
| 52 | + - edpm_neutron_metadata_old_config_dir.stat.isdir |
| 53 | + block: |
| 54 | + - name: Find config files in old location |
| 55 | + ansible.builtin.find: |
| 56 | + paths: "/var/lib/config-data/ansible-generated/neutron-ovn-metadata-agent" |
| 57 | + file_type: file |
| 58 | + recurse: false |
| 59 | + register: edpm_neutron_metadata_old_config_files |
| 60 | + |
| 61 | + - name: Copy config files to new location |
| 62 | + ansible.builtin.copy: |
| 63 | + src: "{{ item.path }}" |
| 64 | + dest: "{{ edpm_neutron_metadata_agent_config_dir }}/{{ item.path | basename }}" |
| 65 | + remote_src: true |
| 66 | + setype: "container_file_t" |
| 67 | + owner: "{{ ansible_user | default(ansible_user_id) }}" |
| 68 | + group: "{{ ansible_user | default(ansible_user_id) }}" |
| 69 | + mode: "0644" |
| 70 | + loop: "{{ edpm_neutron_metadata_old_config_files.files }}" |
| 71 | + when: |
| 72 | + - edpm_neutron_metadata_old_config_files.files is defined |
| 73 | + - edpm_neutron_metadata_old_config_files.files | length > 0 |
| 74 | + |
| 75 | + - name: Remove old config directory |
| 76 | + ansible.builtin.file: |
| 77 | + path: "/var/lib/config-data/ansible-generated/neutron-ovn-metadata-agent" |
| 78 | + state: absent |
0 commit comments