tripleo-ansible/tripleo_ansible/roles/backup_and_restore/molecule/default/prepare.yml

133 lines
3.4 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: Prepare
hosts: all
become: true
gather_facts: true
pre_tasks:
- name: Check for docker cli
command: "command -v docker"
register: docker_cli
failed_when: false
changed_when: false
- name: Check for docker connection
command: "docker ps"
register: docker_ps
failed_when: false
changed_when: false
- name: set basic user fact
set_fact:
ansible_user: "{{ lookup('env', 'USER') }}"
when:
- ansible_user is undefined
- name: set basic home fact
set_fact:
ansible_user_dir: "{{ lookup('env', 'HOME') }}"
when:
- ansible_user_dir is undefined
roles:
- role: test_deps
- role: install-docker
when:
- (docker_cli.rc != 0) or
(docker_ps.rc != 0)
post_tasks:
- name: Install docker-sdk
pip:
name: docker
virtualenv: "{{ ansible_user_dir }}/test-python"
virtualenv_site_packages: true
- name: Install deps for ReaR
package:
name: "{{ rear_packages }}"
state: present
vars:
rear_packages:
- rear
- syslinux
- genisoimage
- kbd
- puppet
- hiera
- python3-docker
- name: Create hiera config file
file:
path: "{{ ansible_user_dir }}/hiera.yaml"
state: touch
- name: Create hieradata directory
file:
path: "{{ ansible_user_dir }}/hieradata"
state: directory
mode: '0755'
- name: Insert some data into hiera.yaml
copy:
dest: "{{ ansible_user_dir }}/hiera.yaml"
content: |
---
:backends:
- json
:json:
:datadir: {{ ansible_user_dir }}/hieradata
:hierarchy:
- service_configs
- name: Insert some data into service_configs.json
copy:
dest: "{{ ansible_user_dir }}/hieradata/service_configs.json"
content: |
{
"mysql::server::root_password": "password"
}
- name: pull some images
docker_image:
name: "{{ item }}"
source: pull
vars:
ansible_python_interpreter: "{{ ansible_user_dir }}/test-python/bin/python"
with_items:
- centos:8
- mysql
- name: Create a data container
docker_container:
name: "{{ item }}"
image: centos:8
detach: true
command: sleep 1d
with_items:
- docker-container1
- docker-container2
vars:
ansible_python_interpreter: "{{ ansible_user_dir }}/test-python/bin/python"
- name: Start myql container
docker_container:
name: mysql
image: mysql
detach: true
env:
MYSQL_ROOT_PASSWORD: password