Search code examples
sshkubernetesansiblekubespray

["Shared connection closed."], "stdout": "sudo: a password is required\r\n while using Ansible playbook


I am trying to run one Ansible playbook for deploying Kubernetes cluster using the tool kubespray on Ubuntu 16.04 OS. I have one base machine which is installed with Ansible and cloned kubespray Git repository. And one master and two worker nodes containing in cluster.

My host (Updated) file like the followig screenshot,

[all]
MILDEVKUB020 ansible_ssh_host=MILDEVKUB020 ip=192.168.16.173 ansible_user=uName  ansible_ssh_pass=pwd
MILDEVKUB030 ansible_ssh_host=MILDEVKUB030 ip=192.168.16.176 ansible_user=uName  ansible_ssh_pass=pwd
MILDEVKUB040 ansible_ssh_host=MILDEVKUB040 ip=192.168.16.177 ansible_user=uName  ansible_ssh_pass=pwd

[kube-master]
MILDEVKUB020

[etcd]
MILDEVKUB020

[kube-node]
MILDEVKUB020
MILDEVKUB030
MILDEVKUB040

[k8s-cluster:children]
kube-master
kube-node

Location of hosts.ini file is /inventory/sample. And I am trying the following Ansible command

sudo ansible-playbook -i inventory/sample/hosts.ini cluster.yml --user=uName --extra-vars "ansible_sudo_pass=pwd"

And I am using the playbook "cluster.yml" from the following link

https://github.com/kubernetes-sigs/kubespray/blob/master/cluster.yml

And my /etc/hosts file containing the entries ,

127.0.0.1 MILDEVDCR01.Milletech.us MILDEVDCR01
192.168.16.173 MILDEVKUB020.Milletech.us MILDEVKUB020
192.168.16.176 MILDEVKUB030.Milletech.us MILDEVKUB030
192.168.16.177 MILDEVKUB040.Milletech.us MILDEVKUB040

Updated error

TASK [adduser : User | Create User Group] 
Thursday 04 April 2019  11:34:55 -0400 (0:00:00.508)       0:00:33.383 ********
fatal: [MILDEVKUB040]: FAILED! => {"changed": false, "msg": "groupadd: Permission denied.\ngroupadd: cannot lock /etc/group; try again later.\n", "name": "kube-cert"}
fatal: [MILDEVKUB020]: FAILED! => {"changed": false, "msg": "groupadd: Permission denied.\ngroupadd: cannot lock /etc/group; try again later.\n", "name": "kube-cert"}
fatal: [MILDEVKUB030]: FAILED! => {"changed": false, "msg": "groupadd: Permission denied.\ngroupadd: cannot lock /etc/group; try again later.\n", "name": "kube-cert"}

I am getting error like this even if I am able to connect all machine from base machine using ssh. How can I trace what is my issue for running this command to deploy Kubernetes cluster?


Solution

  • After trying lot of research I found that need to put the parameters "--ask-pass --become --ask-become-pass" when we are running the ansible playbook. I tried the following command,

    sudo ansible-playbook -i inventory/sample/hosts.ini cluster.yml --user=docker --ask-pass --become --ask-become-pass
    

    And , when it is continuing with kubernetes cluster deployment , it will again arise the problem of inventory name need to use only with small letteres. So I edited all the inventory name and etc/hostname and /etc/hosts with small case hostname . And also putted all small letters in inventory file. Now its working successfully.

    the /etc/hosts contain like following,

    127.0.0.1 MILDEVDCR01.Milletech.us mildevdcr01
    192.168.16.173 MILDEVKUB020.Milletech.us mildevkub020
    192.168.16.176 MILDEVKUB030.Milletech.us mildevkub030
    192.168.16.177 MILDEVKUB040.Milletech.us mildevkub040
    

    etc/hostname

    mildevdcr01
    

    And hosts.ini file like the following,

    [all]
    mildevkub020 ansible_ssh_host=mildevkub020 ip=192.168.16.173 ansible_user=uName  
    ansible_ssh_pass=pwd
    mildevkub030 ansible_ssh_host=mildevkub030 ip=192.168.16.176 ansible_user=uName  
    ansible_ssh_pass=pwd
    mildevkub040 ansible_ssh_host=mildevkub040 ip=192.168.16.177 ansible_user=uName  
    ansible_ssh_pass=pwd
    
    [kube-master]
    mildevkub020
    
    [etcd]
    mildevkub020
    
    [kube-node]
    mildevkub020
    mildevkub030
    mildevkub040
    
    [k8s-cluster:children]
    kube-master
    kube-node
    

    It we are doing like this, we will get the deployed Kubernetes cluster on destination host machines.