Skip to content
Snippets Groups Projects
Commit a0f1cae0 authored by Erik Reid's avatar Erik Reid
Browse files

use when/block ...

parent f3beda0f
No related branches found
No related tags found
No related merge requests found
...@@ -3,20 +3,18 @@ ...@@ -3,20 +3,18 @@
name: "{{ image.image_name }}:{{ image.image_tag }}" name: "{{ image.image_name }}:{{ image.image_tag }}"
register: image_exists register: image_exists
- name: Stop if image exists - name: Build image if necessary
ansible.builtin.meta: end_play when: image_exists.images | length == 0
when: image_exists.images | length > 0 block:
- name: Get VM image
- name: Get VM image amazon.aws.aws_s3:
amazon.aws.aws_s3: aws_access_key: "{{ s3.access_key }}"
aws_access_key: "{{ s3.access_key }}" aws_secret_key: "{{ s3.secret_key }}"
aws_secret_key: "{{ s3.secret_key }}" region: "{{ s3.region }}"
region: "{{ s3.region }}" bucket: "{{ s3.bucket }}"
bucket: "{{ s3.bucket }}" object: "{{ image.vm_image }}"
object: "{{ image.vm_image }}" dest: "$HOME/vrnetlab/{{ image.integration }}/{{ image.vm_image }}"
dest: "$HOME/vrnetlab/{{ image.integration }}/{{ image.vm_image }}" mode: get
mode: get - name: Build/install the docker image
community.general.make:
- name: Build/install the docker image chdir: "$HOME/vrnetlab/{{ image.integration }}"
community.general.make:
chdir: "$HOME/vrnetlab/{{ image.integration }}"
...@@ -3,40 +3,23 @@ ...@@ -3,40 +3,23 @@
name: "{{ image.image_name }}:{{ image.image_tag }}" name: "{{ image.image_name }}:{{ image.image_tag }}"
register: image_exists register: image_exists
- name: Stop if image exists - name: Add docker image if necessary
ansible.builtin.meta: end_play when: image_exists.images | length == 0
when: image_exists.images | length > 0 block:
- name: Get VM images
- name: Get VM images amazon.aws.aws_s3:
amazon.aws.aws_s3: aws_access_key: "{{ s3.access_key }}"
aws_access_key: "{{ s3.access_key }}" aws_secret_key: "{{ s3.secret_key }}"
aws_secret_key: "{{ s3.secret_key }}" region: "{{ s3.region }}"
region: "{{ s3.region }}" bucket: "{{ s3.bucket }}"
bucket: "{{ s3.bucket }}" object: "{{ image.filename }}"
object: "{{ image.filename }}" dest: "/tmp/{{ image.filename }}"
dest: "/tmp/{{ image.filename }}" mode: get
mode: get - name: Add docker images
# community.docker.docker_image doesn't work in this case
# - name: Add docker images ansible.builtin.shell:
# community.docker.docker_image: cmd: "docker image import /tmp/{{ image.filename }} {{ image.image_name }}:{{ image.image_tag }}"
# docker_host: "unix:/run/docker.sock" - name: Remove downloaded file
# name: "{{ item.image_name }}" ansible.builtin.file:
# tag: "{{ item.image_tag }}" path: "/tmp/{{ image.filename }}"
# load_path: "/tmp/{{ item.filename }}" state: absent
# source: load
# state: present
# loop:
# - filename: cEOS-lab-4.28.2.1F.tar
# image_name: ceos
# image_tag: 4.28.1.1F
- name: Add docker images
# community.docker.docker_image doesn't work in this case
ansible.builtin.shell:
cmd: "docker image import /tmp/{{ image.filename }} {{ image.image_name }}:{{ image.image_tag }}"
- name: Remove downloaded file
ansible.builtin.file:
path: "/tmp/{{ image.filename }}"
state: absent
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
version: v0.8.1 version: v0.8.1
dest: $HOME/vrnetlab dest: $HOME/vrnetlab
# - name: Build vrnetlab images - name: Build vrnetlab images
# ansible.builtin.include_tasks: build_image.yml ansible.builtin.include_tasks: build_image.yml
# loop: "{{ vrnetlab_images }}" loop: "{{ vrnetlab_images }}"
# loop_control: loop_control:
# loop_var: image loop_var: image
- name: Import normal images - name: Import normal images
ansible.builtin.include_tasks: import_image.yml ansible.builtin.include_tasks: import_image.yml
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment