Reputation: 125
hosts: all become: true tasks:
name: Creating a docker image command: docker build -t simple-devops-image:latest . args: chdir: /opt/docker
name: Creating the tag for the image command: docker tag simple-devops-image kmurugandocker/simple-devops-image
name: Pushing docker image to DockerHub command: docker push kmurugandocker/simple-devops-image
name: Remove docker images from ansible server command: docker rmi simple-devops-image:latest kmurugandocker/simple-devops-image
TASK [Pushing docker image to DockerHub] ************************************************************************************* fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["docker", "push", "kmurugandocker/simple-devops-image"], "delta": "0:00:00.080293", "end": "2020-04-13 06:30:58.425962", "msg": "non-zero return code", "rc": 1, "start": "2020-04-13 06:30:58.345669", "stderr": "denied: requested access to the resource is denied", "stderr_lines": ["denied: requested access to the resource is denied"], "stdout": "The push refers to a repository [docker.io/kmurugandocker/simple-devops-image]\n75137f74451a: Preparing\nfb8f657b05a7: Preparing\n87af55901360: Preparing\n81349fc07565: Preparing\n892007193bb6: Preparing\ne811ee12aa10: Preparing\n23f8d486123a: Preparing\nafae6f50abb9: Preparing\n136a15f81f25: Preparing\n185574602537: Preparing\n24efcd549ab5: Preparing\ne811ee12aa10: Waiting\n23f8d486123a: Waiting\nafae6f50abb9: Waiting\n136a15f81f25: Waiting\n185574602537: Waiting\n24efcd549ab5: Waiting", "stdout_lines": ["The push refers to a repository [docker.io/kmurugandocker/simple-devops-image]", "75137f74451a: Preparing", "fb8f657b05a7: Preparing", "87af55901360: Preparing", "81349fc07565: Preparing", "892007193bb6: Preparing", "e811ee12aa10: Preparing", "23f8d486123a: Preparing", "afae6f50abb9: Preparing", "136a15f81f25: Preparing", "185574602537: Preparing", "24efcd549ab5: Preparing", "e811ee12aa10: Waiting", "23f8d486123a: Waiting", "afae6f50abb9: Waiting", "136a15f81f25: Waiting", "185574602537: Waiting", "24efcd549ab5: Waiting"]}
Upvotes: 0
Views: 2176
Reputation: 337
you are having this issue because you are running the playbook as a root user, but on the target system you haven't logged in to docker hub with the root user. to solve this issue you can either: remove
become:true
in the playbook which means that it's not a must to be root.
or run:
docker login
as a root in managed hosts.
(plus) you may also want to delete existed images manually in the first time.
Upvotes: 1
Reputation: 19
If you check logs closely, error message says access denied which simply means either you don't have access or you are not logged in to your docker registry
["denied: requested access to the resource is denied"]
Solution: you need to login to your remote docker registry.
docker login
Refer docker documentation for detailed information.
https://docs.docker.com/engine/reference/commandline/login/
Upvotes: 0