0f2b104213
This change bumps up the maximum supported Ansible version to 4.x (ansible-core 2.11.x) and minimum to 2.10. This synchronises Kayobe with Kolla Ansible (see change I8b9212934dfab3831986e8db55671baee32f4bbd). Uses of docker_image are updated. We must now provide the source parameter. When source is build (for molecule), we replace force by force_source and force_tag and move path and dockerfile under the build parameter. Use docker_image_info instead of docker_image_facts. Handle update of ansible inside kolla-ansible virtualenv and document how to do it for the kayobe virtualenv. Change-Id: I7a4530f4f63ddb37aa30a617db5944b97bc3e17f
64 lines
2.5 KiB
YAML
64 lines
2.5 KiB
YAML
---
|
|
- name: Create
|
|
hosts: localhost
|
|
connection: local
|
|
gather_facts: false
|
|
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
|
|
vars:
|
|
molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
|
|
molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}"
|
|
molecule_scenario_directory: "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}"
|
|
molecule_yml: "{{ lookup('file', molecule_file) | community.molecule.from_yaml }}"
|
|
tasks:
|
|
- name: Create Dockerfiles from image names
|
|
template:
|
|
src: "{{ molecule_scenario_directory }}/Dockerfile.j2"
|
|
dest: "{{ molecule_ephemeral_directory }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}"
|
|
with_items: "{{ molecule_yml.platforms }}"
|
|
register: platforms
|
|
|
|
- name: Discover local Docker images
|
|
docker_image_info:
|
|
name: "molecule_local/{{ item.item.name }}"
|
|
with_items: "{{ platforms.results }}"
|
|
register: docker_images
|
|
|
|
- name: Build an Ansible compatible image
|
|
docker_image:
|
|
name: "molecule_local/{{ item.item.image }}"
|
|
source: build
|
|
build:
|
|
path: "{{ molecule_ephemeral_directory }}"
|
|
dockerfile: "{{ item.item.dockerfile | default(item.invocation.module_args.dest) }}"
|
|
force_source: "{{ item.item.force | default(true) }}"
|
|
force_tag: "{{ item.item.force | default(true) }}"
|
|
with_items: "{{ platforms.results }}"
|
|
when: platforms.changed or docker_images.results | map(attribute='images') | select('equalto', []) | list | count >= 0
|
|
|
|
- name: Create molecule instance(s)
|
|
docker_container:
|
|
name: "{{ item.name }}"
|
|
hostname: "{{ item.name }}"
|
|
image: "molecule_local/{{ item.image }}"
|
|
state: started
|
|
recreate: false
|
|
log_driver: json-file
|
|
command: "{{ item.command | default('bash -c \"while true; do sleep 10000; done\"') }}"
|
|
privileged: "{{ item.privileged | default(omit) }}"
|
|
volumes: "{{ item.volumes | default(omit) }}"
|
|
capabilities: "{{ item.capabilities | default(omit) }}"
|
|
ports: "{{ item.exposed_ports | default(omit) }}"
|
|
ulimits: "{{ item.ulimits | default(omit) }}"
|
|
register: server
|
|
with_items: "{{ molecule_yml.platforms }}"
|
|
async: 7200
|
|
poll: 0
|
|
|
|
- name: Wait for instance(s) creation to complete
|
|
async_status:
|
|
jid: "{{ item.ansible_job_id }}"
|
|
register: docker_jobs
|
|
until: docker_jobs.finished
|
|
retries: 300
|
|
with_items: "{{ server.results }}"
|