tripleo-ansible/tripleo_ansible/roles/tripleo_ceph_uuid/tasks/prepare.yml

49 lines
2.1 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: generate nodes-uuid data file
copy:
dest: "{{ playbook_dir }}/ceph-ansible/nodes_uuid_data.json"
content: "{{ uuid_content }}"
- name: generate nodes-uuid playbook
copy:
dest: "{{ playbook_dir }}/ceph-ansible/nodes_uuid_playbook.yml"
content: |
- hosts: all
gather_facts: no
tasks:
- name: set nodes data
set_fact:
nodes_data: "{% raw %}{{ lookup('file','./nodes_uuid_data.json') | from_json }}{% endraw %}"
- name: register machine id
become: true
# awk strips unwanted output, see LP bug #1762460
shell: >-
dmidecode -s system-uuid | \
awk 'match($0, /[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/) { print substr($0, RSTART, RLENGTH) }' | \
tr A-F a-f
register: machine_uuid
# NOTE(tonyb): 0 == no error, 1 == -EPERM or bad data and 2 == Command not found
# 1 and 2 aren't great but shouldn't cause the deploy to fail. If we're using
# the node specific data we'll fail then. If we aren't then lets keep moving
failed_when: machine_uuid.rc not in [0, 1, 2]
- name: generate host vars from nodes data
copy:
content: "{% raw %}{{ nodes_data[machine_uuid.stdout|default('')]|default({})|to_nice_yaml }}{% endraw %}"
dest: "{{ playbook_dir }}/ceph-ansible/host_vars/{% raw %}{{ inventory_hostname }}{% endraw %}.yml"
delegate_to: localhost