why kubespray ansible can't match the hosts

1.9k views Asked by At

I was install kubernetes by kubespray, my kubespray version is v2.11.0, I follow the official documentation to install step by step. but when i exec the "ansible-playbook -i inventory/mycluster/hosts.yml --become --become-user=root cluster.yml" i get the below info that can't match the hosts.

root@yinkai01:~/kubespray# ansible-playbook -i inventory/mycluster/hosts.yml --become --become-user=root cluster.yml
/usr/local/lib/python3.5/dist-packages/ansible/parsing/vault/__init__.py:41: CryptographyDeprecationWarning: Python 3.5 support will be dropped in the next release ofcryptography. Please upgrade your Python.
  from cryptography.exceptions import InvalidSignature
 [WARNING]: Unable to parse /root/kubespray/inventory/mycluster/hosts.yml as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


PLAY [localhost] **********************************************************************************************************************************************************

TASK [Check ansible version >=2.7.8] **************************************************************************************************************************************
Saturday 10 October 2020  07:20:40 -0400 (0:00:00.089)       0:00:00.089 ****** 
ok: [localhost] => {
    "changed": false,
    "msg": "All assertions passed"
}
 [WARNING]: Could not match supplied host pattern, ignoring: bastion


PLAY [bastion[0]] *********************************************************************************************************************************************************
skipping: no hosts matched
 [WARNING]: Could not match supplied host pattern, ignoring: k8s-cluster

 [WARNING]: Could not match supplied host pattern, ignoring: etcd


PLAY [k8s-cluster:etcd] ***************************************************************************************************************************************************
skipping: no hosts matched

PLAY [k8s-cluster:etcd] ***************************************************************************************************************************************************
skipping: no hosts matched

PLAY [etcd] ***************************************************************************************************************************************************************
skipping: no hosts matched

PLAY [k8s-cluster] ********************************************************************************************************************************************************
skipping: no hosts matched

PLAY [k8s-cluster] ********************************************************************************************************************************************************
skipping: no hosts matched
 [WARNING]: Could not match supplied host pattern, ignoring: kube-master


PLAY [kube-master] ********************************************************************************************************************************************************
skipping: no hosts matched

PLAY [k8s-cluster] ********************************************************************************************************************************************************
skipping: no hosts matched
 [WARNING]: Could not match supplied host pattern, ignoring: calico-rr


PLAY [calico-rr] **********************************************************************************************************************************************************
skipping: no hosts matched

PLAY [kube-master[0]] *****************************************************************************************************************************************************
skipping: no hosts matched

PLAY [kube-master] ********************************************************************************************************************************************************
skipping: no hosts matched

PLAY [kube-master] ********************************************************************************************************************************************************
skipping: no hosts matched

PLAY [k8s-cluster] ********************************************************************************************************************************************************
skipping: no hosts matched

PLAY RECAP ****************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0   

Saturday 10 October 2020  07:20:40 -0400 (0:00:00.089)       0:00:00.178 ****** 
=============================================================================== 
Check ansible version >=2.7.8 -------------------------------------------------------------------------------------------------------------------------------------- 0.09s

And I the hosts yaml. I think it's no question about the hosts.yaml, as you can see below:

root@yinkai01:~/kubespray# cat inventory/mycluster/hosts.yaml 
all:
  hosts:
    node1:
      access_ip: 10.138.18.194
      ip: 10.138.18.194
      ansible_host: 10.138.18.194
    node2:
      access_ip: 10.138.18.195
      ip: 10.138.18.195
      ansible_host: 10.138.18.195
    node3:
      access_ip: 10.138.18.196
      ip: 10.138.18.196
      ansible_host: 10.138.18.196
  children:
    kube-master:
      hosts:
        node2:
        node1:
    kube-node:
      hosts:
        node3:
        node2:
        node1:
    etcd:
      hosts:
        node3:
        node2:
        node1:
    k8s-cluster:
      children:
        kube-node:
        kube-master:
    calico-rr:
      hosts: {}
root@yinkai01:~/kubespray#

some one who can tell me, where am I wrong?

2

There are 2 answers

0
YLR On

Just change in your comamnd line the name of the file (a typo apparently) :

inventory/mycluster/hosts.yml

By

inventory/mycluster/hosts.yaml

This warning help you :

 [WARNING]: No inventory was parsed, only implicit localhost is available
0
Samith Perera On

Clone the repo https://github.com/kubernetes-sigs/kubespray.git

sudo pip3 install -r requirements.txt
sudo cp -rfp inventory/sample/ inventory/mycluster
declare -a IPS=(192.168.56.2 192.168.56.3)
CONFIG_FILE=inventory/mycluster/host.yaml python3 contrib/inventory_builder/inventory.py ${IPS[@]}
sudo ansible-playbook -i ./inventory/mycluster/host.yaml cluster.yml -b