I'm completely new to ansible and I'm having a hard time with it. I have an inventory.yml file which is as the following:
EDIT: changed my inventory.yml now looks as follows inventory.yml:
[master]
master1 ansible_host=192.168.56.2 ansible_port=2222 ansible_user=deploy ansible_ssh_pass=vagrant ansible_become_pass=vagrant apt_key_master=https://packages.cloud.google.com/apt/doc/apt-key.gpg
[worker]
worker1 ansible_host=192.168.56.3 ansible_port=2200 ansible_user=deploy ansible_ssh_pass=vagrant ansible_become_pass=vagrant apt_key_worker=https://packages.cloud.google.com/apt/doc/apt-key.gpg
also I have a playbook called kube-repos.yml which is as follows:
EDIT: changed kube-repos.yml now looks as follows: kube-repos.yml:
- hosts: all
become: yes
tasks:
- name: add Kubernetes apt-key
apt_key:
url: "{{ apt_key_master }}"
state: present
- name: add Kubernetes' APT repository
apt_repository:
repo: deb http://apt.kubernetes.io/ kubernetes-xenial main
state: present
when I apply my ansible playbook using ansible-playbook kube-repos.yml
I get the following error:
fatal: [master1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey).", "unreachable": true}
fatal: [worker1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey).", "unreachable": true}
I see my problem is getting proper authentication ansible to ssh into the host vm's.
I am able to do vagrant ssh master
and vagrant ssh worker
and get into my vm's perfectly fine but when I apply the playbook and if I use the command ansible all -m ping
I get the UNREACHABLE error. I am trying to setup a simple kubernetes cluster consisting of one master and one worker node.
I am at a loss now because I have read the ansible documentation but still cannot figure out how to correct this error. So I feel like I have no choice but to ask on here. I hope someone is kind enough to help me out and thanks in advance.
EDIT: after the changes suggested by @mikequentel I have the following error:
fatal: [worker1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.56.3 port 2200: Connection refused", "unreachable": true}
fatal: [master1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.56.2 port 2222: Connection refused", "unreachable": true}