Files
bifrost/playbooks/roles/bifrost-create-vm-nodes/tasks/main.yml
Riccardo Pittau 7283e3dc54 Convert with_items to loop
Recommended way to work with loops is now using loop.

Change-Id: I4ce186e16e6ae5b3a6f29542887431f5499286b0
2020-06-11 17:31:28 +02:00

174 lines
6.1 KiB
YAML

# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
#
# 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: produce warning when csv file is defined
debug:
msg: >
"WARNING - Variable 'baremetal_csv_file' is deprecated.
For backward compatibility, its value will be used as path for
file to write data for created 'virtual' baremetal nodes,
but the file will be JSON formatted."
when: baremetal_csv_file is defined
- name: override baremetal_json_file with csv file path
set_fact:
baremetal_json_file: "{{ baremetal_csv_file }}"
when: baremetal_csv_file is defined
# NOTE(cinerama) openSUSE Tumbleweed & Leap have different distribution
# IDs which are not currently accounted for in Ansible, so adjust facts
# so we can have shared defaults for the whole SuSE family.
# This change can be removed when the pull request at
# https://github.com/ansible/ansible/pull/17575 lands in a new version.
- name: Ensure openSUSE Tumbleweed has the correct family
set_fact:
ansible_os_family: "Suse"
when: ansible_os_family is search("openSUSE Tumbleweed")
- name: Ensure openSUSE Leap has the correct family
set_fact:
ansible_os_family: "Suse"
when: (ansible_os_family is search("SUSE LINUX")) or
(ansible_os_family is search("openSUSE Leap"))
# NOTE(hwoarang) The 'apt' module needs python-apt installed in the virtualenv
# but it's not possible to do that. See https://github.com/ansible/ansible/issues/14468
# python-apt only works if it's installed on the local system so we need to switch the
# Ansible python interpreter.
- name: "Update apt cache if Ubuntu/Debian"
apt:
update_cache: yes
when: ansible_os_family == "Debian"
vars:
ansible_python_interpreter: '/usr/bin/python3'
- name: "Load distribution defaults"
include_vars: "{{ item }}"
with_first_found:
- "../defaults/required_defaults_{{ ansible_distribution }}.yml"
- "../defaults/required_defaults_{{ ansible_os_family }}.yml"
- name: "Include OS version-specific defaults"
include_vars: "{{ item }}"
with_first_found:
- "../defaults/required_defaults_{{ ansible_distribution }}_{{ ansible_distribution_release }}.yml"
- "../defaults/required_defaults_{{ ansible_distribution }}_{{ ansible_distribution_version }}.yml"
- "../defaults/dummy-defaults.yml"
# NOTE(cinerama): On Fedora 22, ansible 1.9, ansible_pkg_mgr
# defaults to yum, which may not be installed. This can be safely
# removed when we start using an ansible release which prefers dnf.
- name: "Check for dnf"
stat:
path: "/usr/bin/dnf"
register: test_dnf
- name: "Adjust ansible_pkg_mgr if dnf exists"
set_fact:
ansible_pkg_mgr: "dnf"
when: ansible_distribution == 'Fedora' and test_dnf.stat.exists|bool
# NOTE(hwoarang) The 'apt' module needs python-apt installed in the virtualenv
# but it's not possible to do that. See https://github.com/ansible/ansible/issues/14468
# python-apt only works if it's installed on the local system so we need to switch the
# Ansible python interpreter.
- name: "Install required packages"
action: "{{ ansible_pkg_mgr }} name={{ required_packages }} state=present"
vars:
ansible_python_interpreter: '/usr/bin/python3'
- name: "Set ci_testing_zuul if it appears we are running in upstream OpenStack CI"
set_fact:
ci_testing: true
ci_testing_zuul: true
reqs_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/requirements"
when: lookup('env', 'ZUUL_BRANCH') | length > 0
- name: ensure installation root folder exists
become: yes
file:
state: directory
dest: "{{ git_root }}"
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_gid }}"
- name: download requirements via git
git:
dest: "{{ reqs_git_folder }}"
force: yes
repo: "{{ reqs_git_url }}"
version: "{{ reqs_git_branch }}"
update: yes
clone: yes
when: ci_testing_zuul | bool == false and copy_from_local_path | bool == false
- name: copy requirements from local path
command: cp -a {{ reqs_git_url }} {{ reqs_git_folder }} creates={{ reqs_git_folder }}
when: ci_testing_zuul | bool == true or copy_from_local_path | bool == true
- include: prepare_libvirt.yml
- name: truncate explicit list of vm names
set_fact:
test_vm_node_names: "{{ test_vm_node_names[:(test_vm_num_nodes|int)] }}"
- name: generate test vm names
set_fact:
generated_test_vm_node_names: "{{ generated_test_vm_node_names|default([]) + [item] }}"
with_sequence: count={{ test_vm_num_nodes | int }} format={{ test_vm_node_name_base }}%i
when: test_vm_node_names | length == 0
- name: set test vm names
set_fact:
test_vm_node_names: "{{ generated_test_vm_node_names }}"
when: test_vm_node_names | length == 0
- name: create placeholder var for vm entries in JSON format
set_fact:
testvm_json_data: {}
testvm_nodes_json: []
- include: create_vm.yml
loop: "{{ test_vm_node_names }}"
- name: write to baremetal json file
copy:
dest: "{{ baremetal_json_file }}"
content: "{{ testvm_json_data | to_nice_json }}"
- name: write to nodes json
copy:
dest: "{{ baremetal_nodes_json }}"
content: "{{ {'nodes': testvm_nodes_json} | to_nice_json }}"
- name: >
"Set file permissions such that the baremetal data file
can be read by the user executing Ansible"
file:
path: "{{ baremetal_json_file }}"
owner: "{{ ansible_env.SUDO_USER }}"
when: >
ansible_env.SUDO_USER is defined and
baremetal_json_file != ""
- name: >
"Set file permissions such that the nodes json file
can be read by the user executing Ansible"
file:
path: "{{ baremetal_nodes_json }}"
owner: "{{ ansible_env.SUDO_USER }}"
when: >
ansible_env.SUDO_USER is defined and
baremetal_nodes_json != ""