tripleo-ansible/tripleo_ansible/roles/tripleo_upgrade_hiera/tasks/create-tripleo-upgrade-file.yml
Lukas Bezdicka b066abcb2e Fix logic to stop overrwriting upgrade hieradata
Change-Id: I5eade126445358dbe20140af78665d9747db18de
2020-03-04 00:14:50 +01:00

55 lines
1.6 KiB
YAML

---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# 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: create the directory for hiera file
file:
path: "{{ tripleo_upgrade_hiera_file | dirname }}"
owner: "root"
group: "root"
mode: 0755
state: directory
become: true
- name: check if the upgrade file exists.
stat:
path: "{{ tripleo_upgrade_hiera_file }}"
register: _tripleo_upgrade_hiera_file
become: true
- name: check if the file contains valid json
command: "jq . {{ tripleo_upgrade_hiera_file }}"
register: _tripleo_upgrade_hiera_test
become: true
when:
- _tripleo_upgrade_hiera_file.stat.exists | bool
- name: create the hiera file when no file or empty file.
copy:
dest: "{{ tripleo_upgrade_hiera_file }}"
owner: "root"
group: "root"
mode: 0644
content: "{}"
become: true
when:
- not (_tripleo_upgrade_hiera_file.stat.exists | bool) or
not (_tripleo_upgrade_hiera_test.stdout | length) > 0
- name: load the json hiera data
command: "jq . {{ tripleo_upgrade_hiera_file }}"
register: tripleo_upgrade_hiera_command
become: true