k3s-io / k3s-ansible

Apache License 2.0
1.89k stars 780 forks source link

With multiple agent hosts, ansible appears to be concatenating host IPs #248

Closed ntwyman closed 7 months ago

ntwyman commented 8 months ago

My inventory file

k3s_cluster:
  children:
    server:
      hosts:
        10.10.0.91
    agent:
      hosts:
        10.10.0.95
        10.10.0.94

  # Required Vars
  vars:
    ansible_port: 22
    ansible_user: nick
    k3s_version: v1.26.9+k3s1
    token: "mytoken"  # Use ansible vault if you want to keep it secret
    api_endpoint: "{{ hostvars[groups['server'][0]]['ansible_host'] | default(groups['server'][0]) }}"
    extra_server_args: ""
    extra_agent_args: ""

  # Optional vars
    # api_port: 6443
    # k3s_server_location: /var/lib/rancher/k3s
    # systemd_dir: /etc/systemd/system
    # extra_service_envs: [ 'ENV_VAR1=VALUE1', 'ENV_VAR2=VALUE2' ]
    # List of locally available manifests to apply to the cluster, useful for PVCs or Traefik modifications.
    # Manifests should be either full paths or relative to the playbook directory.
    # extra_manifests: [ '/path/to/manifest1.yaml', '/path/to/manifest2.yaml' ]

When I run this

$ ansible-playbook playbook/site.yml -i inventory.yml

I get

PLAY [Cluster prep] ****************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************
[WARNING]: Unhandled error in Python interpreter discovery for host 10.10.0.95 10.10.0.94: Failed to connect to the host via ssh:
ssh: Could not resolve hostname 10.10.0.95 10.10.0.94: nodename nor servname provided, or not known
fatal: [10.10.0.95 10.10.0.94]: UNREACHABLE! => {"changed": false, "msg": "Data could not be sent to remote host \"10.10.0.95 10.10.0.94\". Make sure this host can be reached over ssh: ssh: Could not resolve hostname 10.10.0.95 10.10.0.94: nodename nor servname provided, or not known\r\n", "unreachable": true}
^C [ERROR]: User interrupted execution

If I run this with just one agent host IP (either one) it works fine. Seems to be incorrectly parsing the yaml file. For reference

$ ansible-playbook --version
ansible-playbook [core 2.15.6]
  config file = /Users/nick/Downloads/k3s-ansible-master/ansible.cfg
  configured module search path = ['/Users/nick/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/8.6.1/libexec/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/nick/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible-playbook
  python version = 3.12.0 (main, Oct  2 2023, 12:03:24) [Clang 15.0.0 (clang-1500.0.40.1)] (/opt/homebrew/Cellar/ansible/8.6.1/libexec/bin/python)
  jinja version = 3.1.2
  libyaml = True
garb4ge commented 8 months ago

I faced the same "issue". However, when looking at the YAML inventory description in the ansible documentation, there are trailing colons at the end of the host definitions, so in your case

k3s_cluster:
  children:
    server:
      hosts:
        10.10.0.91:
    agent:
      hosts:
        10.10.0.95:
        10.10.0.94:

will work. We should update the README and the example though.

ntwyman commented 7 months ago

Yup that's it - thanks.