最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

automation - Ansible errors when pulling list of docker images "invalid reference format" - Stack Overflow

programmeradmin2浏览0评论

I'm currently having an issue when trying to pull a list of Docker images with Ansible.

My goal is to pull multiple Docker images with Ansible and automatically tag and upload them to our local registry.

Therefore my idea was to use a variable with all our containers:

docker-container:
  - mariadb
  - guacamole

and then use my task with:

- name: Pull docker container
  community.docker.docker_image:
    name: "{{ docker-container }}"
    source: pull

resulting in:

TASK [docker_registry : Pull image] *******************************

fatal: [192.168.2.20]: FAILED! => {"changed": false, "msg": "Error pulling image ['mariadb', 'guacamole']:latest - 400 Client Error for http+docker://localhost/v1.48/images/create?tag=latest&fromImage=%5B%27mariadb%27%2C+%27guacamole%27%5D: Bad Request (\"invalid reference format\")"}

Pulling each image on its own works, but using a list shouldn't be that hard, right?
It seems like Ansible doesn't use the list as expected but I also don't understand why.

I'm currently having an issue when trying to pull a list of Docker images with Ansible.

My goal is to pull multiple Docker images with Ansible and automatically tag and upload them to our local registry.

Therefore my idea was to use a variable with all our containers:

docker-container:
  - mariadb
  - guacamole

and then use my task with:

- name: Pull docker container
  community.docker.docker_image:
    name: "{{ docker-container }}"
    source: pull

resulting in:

TASK [docker_registry : Pull image] *******************************

fatal: [192.168.2.20]: FAILED! => {"changed": false, "msg": "Error pulling image ['mariadb', 'guacamole']:latest - 400 Client Error for http+docker://localhost/v1.48/images/create?tag=latest&fromImage=%5B%27mariadb%27%2C+%27guacamole%27%5D: Bad Request (\"invalid reference format\")"}

Pulling each image on its own works, but using a list shouldn't be that hard, right?
It seems like Ansible doesn't use the list as expected but I also don't understand why.

Share Improve this question edited Mar 17 at 17:41 β.εηοιτ.βε 39.5k14 gold badges79 silver badges99 bronze badges asked Mar 17 at 16:50 YazarYazar 374 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

Because the module expect you to pull one unique image at a time, not a list of images.
You can use a loop, though to achieve what you want.

- name: Pull docker container
  community.docker.docker_image:
    name: "{{ item }}"
    source: pull
  loop: "{{ docker_container }}"
  vars:
    docker_container:
      - mariadb
      - guacamole

Which would result in:

TASK [Pull docker container] *************************************************
changed: [localhost] => (item=mariadb)
changed: [localhost] => (item=guacamole)

Also mind that variables should not contain hyphen (-), use underscores (_), instead.
Further reading: in Creating valid variable names.

发布评论

评论列表(0)

  1. 暂无评论