Ahmad_20
Ahmad_20

Reputation: 33

How to use docker_image and docker_container module in Ansible

I would like to make a simple script that can deploy and download docker image from docker hub using Ansible but when I am trying to execute mycode I experience some errors as follows:

PLAY [manage docker using ansible] *********************************************

TASK [Gathering Facts] *********************************************************
ok: [controller]
ok: [worker]

TASK [ping hosts] **************************************************************
ok: [controller]
ok: [worker]

TASK [pull docker image] *******************************************************
fatal: [controller]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (docker_image) module: source Supported parameters include: api_version,archive_path,buildargs,cacert_path,cert_path,container_limits,debug,docker_host,dockerfile,filter_logger,force,http_timeout,key_path,load_path,name,nocache,path,pull,push,repository,rm,ssl_version,state,tag,timeout,tls,tls_hostname,tls_verify,use_tls"}
fatal: [worker]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (docker_image) module: source Supported parameters include: api_version,archive_path,buildargs,cacert_path,cert_path,container_limits,debug,docker_host,dockerfile,filter_logger,force,http_timeout,key_path,load_path,name,nocache,path,pull,push,repository,rm,ssl_version,state,tag,timeout,tls,tls_hostname,tls_verify,use_tls"}
        to retry, use: --limit @/home/testuser/docker_manage.retry

PLAY RECAP *********************************************************************
controller                 : ok=2    changed=0    unreachable=0    failed=1
worker                     : ok=2    changed=0    unreachable=0    failed=1

here is my code:

---
 - name: manage docker using ansible
   hosts: all
   become: true
   tasks:
    - name: ping hosts
      ping:
    - name: pull docker image
      docker_image:
       name: busybox
       source: pull
    - name: deploy container
      docker_container:
       name: first_container
       image: busybox
       state: present

I have tried to follow guide on this [link] (https://docs.ansible.com/ansible/latest/scenario_guides/guide_docker.html) to config my ansible.cfg file.

Upvotes: 3

Views: 5209

Answers (1)

Zeitounator
Zeitounator

Reputation: 44595

Unsupported parameters for (docker_image) module: source

Although you did not provide your ansible version in your question, I'm quite sure you need to upgrade (or to remove this parameter). The source parameter was added in ansible 2.8

Ref: https://docs.ansible.com/ansible/latest/modules/docker_image_module.html#parameter-source

Upvotes: 4

Related Questions