techno-tim / k3s-ansible

The easiest way to bootstrap a self-hosted High Availability Kubernetes cluster. A fully automated HA k3s etcd install with kube-vip, MetalLB, and more. Build. Destroy. Repeat.
https://technotim.live/posts/k3s-etcd-ansible/
Apache License 2.0
2.41k stars 1.05k forks source link

Unable to parse hosts.ini as an inventory source #208

Closed acdoussan closed 1 year ago

acdoussan commented 1 year ago

When running the ansible playbook, either with the default hosts.ini or one modified to have the right ips, I get the following.

$ ansible-inventory --list                        
[WARNING]: Unable to parse /Users/acdoussan/git/homelab/ansible/k3s-ansible/hosts.ini as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

hosts.ini contains:

[master]
192.168.30.38
192.168.30.39
192.168.30.40

[node]
192.168.30.41
192.168.30.42

[k3s_cluster:children]
master
node

Expected Behavior

the provided example should work

Current Behavior

The provided example does not work.

Steps to Reproduce

  1. Copy the sample folder as directed
  2. Try to run the playbook, or try to run ansible-inventory --list
  3. playbook fails with unable to parse hosts.ini

Context (variables)

Operating system: MacOS 12.6 Montery

Ansible version:

$ ansible --version
ansible [core 2.12.5]
  config file = /Users/acdoussan/git/homelab/ansible/k3s-ansible/ansible.cfg
  configured module search path = ['/Users/acdoussan/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/5.8.0/libexec/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/acdoussan/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.10.4 (main, Apr 26 2022, 19:36:29) [Clang 13.1.6 (clang-1316.0.21.2)]
  jinja version = 3.1.2
  libyaml = True

Hardware: N/A

Variables Used

all.yml

k3s_version: ""
ansible_user: NA
systemd_dir: ""

flannel_iface: ""

apiserver_endpoint: ""

k3s_token: "NA"

extra_server_args: ""
extra_agent_args: ""

kube_vip_tag_version: ""

metal_lb_speaker_tag_version: ""
metal_lb_controller_tag_version: ""

metal_lb_ip_range: ""

Hosts

host.ini

[master]
IP.ADDRESS.ONE
IP.ADDRESS.TWO
IP.ADDRESS.THREE

[node]
IP.ADDRESS.FOUR
IP.ADDRESS.FIVE

[k3s_cluster:children]
master
node

Possible Solution

I tried running chmod 744 on the hosts.ini file, no difference. ref: https://bobcares.com/blog/ansible-unable-to-parse-as-an-inventory-source/

acdoussan commented 1 year ago

Turns out I did several things wrong here.

First, I was trying to use a non-existent inventory file (I was running ansible-playbook site.yml -i inventory/my-cluster/hosts.ini, no my-cluster folder exists, not sure how I ended up with that, maybe something wrong with tab completion).

Second, the ansible-inventory --list reads the ansible.cfg file, which is configured by default with ./hosts.ini, which doesn't exist.

Might be good to update the ansible.cfg to point to the sample hosts.ini, but otherwise I think this can be closed, this was just an operator error.

timothystewart6 commented 1 year ago

It seems like you partially followed the docs :) All good! I will close this https://docs.technotim.live/posts/k3s-etcd-ansible/