snowdrop / k8s-infra

Information to bootstrap vms using dedicated server, local machine and setup using Ansible Playbooks
Apache License 2.0
29 stars 14 forks source link

Issue: Could not resolve hostname h01-118: nodename nor servname provided, or not known", #192

Closed cmoulliard closed 3 years ago

cmoulliard commented 3 years ago

Issue

When we execute the following commands

export k8s_version=118
export VM_NAME=h01-${k8s_version}
export PASSWORD_STORE_DIR=~/.password-store-snowdrop

ansible-playbook hetzner/ansible/hetzner-delete-server.yml -e vm_name=${VM_NAME} -e hetzner_context_name=snowdrop
ansible-playbook ansible/playbook/passstore_controller_inventory_remove.yml -e vm_name=${VM_NAME}  -e pass_provider=hetzner
ansible-playbook ansible/playbook/passstore_controller_inventory.yml -e vm_name=${VM_NAME} -e pass_provider=hetzner -e k8s_type=masters -e k8s_version=${k8s_version} -e operation=create
ansible-playbook hetzner/ansible/hetzner-create-server.yml -e vm_name=${VM_NAME} -e salt_text=$(gpg --gen-random --armor 1 20) -e hetzner_context_name=snowdrop -e pass_provider=hetzner -e k8s_type=masters -e k8s_version=${k8s_version}
ansible-playbook ansible/playbook/sec_host.yml -e vm_name=${VM_NAME} -e provider=hetzner

under k8s-infra project, then ansible reports the following error during the execution of the role sec_host

TASK [Gathering Facts] *****************************************************************************************************************************************************************************************************************
task path: /Users/cmoullia/code/snowdrop/infra-jobs-productization/k8s-infra/ansible/playbook/sec_host.yml:2
Friday 19 February 2021  09:15:42 +0100 (0:00:00.140)       0:00:00.140 ******* 
<h01-118> ESTABLISH SSH CONNECTION FOR USER: snowdrop
<h01-118> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o 'IdentityFile="/Users/cmoullia/.ssh/id_rsa_snowdrop_hetzner_h01-118"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="snowdrop"' -o ConnectTimeout=10 -o ControlPath=/Users/cmoullia/.ansible/cp/0ab23a8fdc h01-118 '/bin/sh -c '"'"'echo ~snowdrop && sleep 0'"'"''
<h01-118> (255, b'', b'ssh: Could not resolve hostname h01-118: nodename nor servname provided, or not known\r\n')
fatal: [h01-118]: UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname h01-118: nodename nor servname provided, or not known",
    "unreachable": true
}

Is the problem related to another issue which is that the property ansible_ssh_host does not exist ?

 pass-team hetzner/h01-118
hetzner/h01-118
├── ansible_ssh_port
├── groups
│   ├── k8s_118
│   └── masters
├── id_rsa
├── id_rsa.pub
├── os_password
├── os_user
└── ssh_port

The ansible_ssh_host is not created during the execution of this playbook :

ansible-playbook ansible/playbook/passstore_controller_inventory.yml -e vm_name=${VM_NAME} -e pass_provider=hetzner -e k8s_type=masters -e k8s_version=${k8s_version} -e operation=create -vvv

See result generated: https://gist.githubusercontent.com/cmoulliard/096729ecc24aa393d8b6dc2194c7ab51/raw/d58baee5946a0796957b335eb8da04fa3826d12b/gistfile1.txt

The ip_address of the vm is well created during the creation of the VM BUT it is not at all stored within the passwordstore db See: https://github.com/snowdrop/k8s-infra/blob/d6ea90e2fbb2e57c94b09c9c4307ad895032a2f2/ansible/roles/hetzner/create_server/tasks/main.yml#L58

jacobdotcosta commented 3 years ago

I'll take a look on why the passwordstore is not storing the ip address correctly.

cmoulliard commented 3 years ago

Another problem is that such a variable os_user is not at all declared/define: https://github.com/snowdrop/k8s-infra/blob/366b00974f530d5662abc7d7f40cc52daa2b25f4/ansible/roles/hetzner/create_server/templates/user-data.j2#L23

jacobdotcosta commented 3 years ago

I have fixed this on my branch.