111 lines
3.1 KiB
YAML
111 lines
3.1 KiB
YAML
---
|
|
#
|
|
# Copyright (c) 2019 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# ROLE DESCRIPTION:
|
|
# This role is to create static configuration and apply the puppet bootstrap
|
|
# manifest.
|
|
|
|
- name: Create config workdir
|
|
file:
|
|
path: "{{ hieradata_workdir }}"
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: 0755
|
|
|
|
- block:
|
|
- name: Generating static config data
|
|
command: "/usr/bin/sysinv-puppet create-static-config {{ hieradata_workdir }}"
|
|
failed_when: false
|
|
register: static_config_result
|
|
|
|
- name: Fail if static hieradata cannot be generated
|
|
fail:
|
|
msg: "Failed to create puppet hiera static config."
|
|
when: static_config_result.rc != 0
|
|
|
|
when: mode == 'bootstrap'
|
|
|
|
- block:
|
|
- name: Set ssh_config tmp dir fact
|
|
set_fact:
|
|
temp_ssh_config_dir: /tmp/config/ssh_config
|
|
|
|
# To work around an ansible quirk that regex_replace filter
|
|
# is ignored when it is applied to variables in the command module
|
|
- name: Strip the leading '/' from directories and assign them to new variables
|
|
set_fact:
|
|
short_puppet_permdir: "{{ puppet_permdir | regex_replace('^\\/', '') }}/hieradata"
|
|
short_ssh_config_permdir: "{{ ssh_config_permdir | regex_replace('^\\/', '') }}"
|
|
|
|
- name: Prefetch static hieradata
|
|
command: >-
|
|
tar -C {{ hieradata_workdir }} -xpf {{ target_backup_dir }}/{{ backup_filename }} --transform='s,.*/,,'
|
|
'{{ short_puppet_permdir }}/*static.yaml'
|
|
args:
|
|
warn: false
|
|
|
|
- name: Look for ssh_config dir in the backup tarball
|
|
shell: "tar -tf {{ target_backup_dir }}/{{ backup_filename }} | grep 'opt/platform/config/.*/ssh_config'"
|
|
args:
|
|
warn: false
|
|
failed_when: false
|
|
register: search_ssh_config
|
|
|
|
- block:
|
|
- name: Create temp ssh_config dir
|
|
file:
|
|
path: "{{ temp_ssh_config_dir }}"
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: 0755
|
|
|
|
- name: Prefetch ssh_config
|
|
command: >-
|
|
tar -C {{ temp_ssh_config_dir }} -xpf {{ target_backup_dir }}/{{ backup_filename }} --transform='s,.*/,,'
|
|
{{ short_ssh_config_permdir }}
|
|
args:
|
|
warn: false
|
|
|
|
- name: Remove the unwanted directory
|
|
file:
|
|
path: "{{ temp_ssh_config_dir }}/ssh_config"
|
|
state: absent
|
|
|
|
when: search_ssh_config.rc == 0
|
|
when: mode == 'restore'
|
|
|
|
- name: Applying puppet bootstrap manifest
|
|
command: >
|
|
/usr/local/bin/puppet-manifest-apply.sh
|
|
{{ hieradata_workdir }}
|
|
{{ derived_network_params.controller_0_address }}
|
|
controller ansible_bootstrap > {{ manifest_apply_log }}
|
|
register: bootstrap_manifest
|
|
environment:
|
|
INITIAL_CONFIG_PRIMARY: "true"
|
|
LC_ALL: "en_US.UTF-8"
|
|
|
|
- name: Fail if puppet manifest apply script returns an error
|
|
fail:
|
|
msg: >-
|
|
Failed to apply bootstrap manifest. See /var/log/puppet/latest/puppet.log
|
|
for details.
|
|
when: bootstrap_manifest.rc != 0
|
|
|
|
- name: Ensure Puppet directory exists
|
|
file:
|
|
path: "{{ puppet_permdir }}"
|
|
state: directory
|
|
recurse: yes
|
|
owner: root
|
|
group: root
|
|
mode: 0755
|
|
|
|
- name: Persist puppet working files
|
|
command: "mv {{ hieradata_workdir }} {{ puppet_permdir }}"
|