I am running ansible on centos machine
[ansadmin@ansible docker]$ ls
Dockerfile hosts simple-devops-image.yml webapp.war
[ansadmin@ansible docker]$ cat hosts
localhost
simple-devops-image.yml
---
- hosts: all
become: true
tasks:
- name: stop current running container
command: docker stop simple-devops-container
ignore_errors: yes
- name: remove stopped container
command: docker rm simple-devops-container
ignore_errors: yes
- name: remove docker image
command: docker rmi simple-devops-image
ignore_errors: yes
- name: build docker image using war
command: docker build -t simple-devops-image .
args:
chdir: /opt/docker
- name: create container using simple image
command: docker run -d --name simple-devops-container -p 8080:8080 simple-devops-image
Even on localhost I am getting permission denied.The user is already with sudo rights.
ansible-playbook -i hosts simple-devops-image.yml --check
PLAY [all] *************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ansadmin@localhost: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}
PLAY RECAP *************************************************************************************************************
localhost : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
ping is working.
[ansadmin@ansible docker]$ ping localhost
PING localhost(localhost (::1)) 56 data bytes
64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.024 ms
64 bytes from localhost (::1): icmp_seq=2 ttl=64 time=0.045 ms
64 bytes from localhost (::1): icmp_seq=3 ttl=64 time=0.045 ms