Search code examples
ansibleansible-inventory

Ansible: No inventory was passed, only implicit localhost is available


I have the following ansible playbook:

$ cat vm_template.yml                 
- name: Create new LXC container in Proxmox
  hosts: 'central.local'
  tasks:
    - name: 'Create container'
      proxmox:
        vmid: '810' # specifying container ID
        api_user: 'root@pam' # Proxmox user
        api_password: '' # password in plaintext
        api_host: '' # proxmox hostname
        password: 'password' # container password in plaintext
        hostname: 'CT-Prometheus-ArchLinux' # container hostname
        node: 'central' # proxmox hostname
        cores: '1'
        cpus: '2'
        cpuunits: '1000'
        ostemplate: 'archlinux-base_20210421-1_amd.tar.gz'
        storage: 'VMs'
        disk: '16'
        memory: '512'
        nameserver: '8.8.8.8'
        netif: '{"net0":"name=eth0,ip=static,bridge=vmbr10"}'
        state: 'present'

and a hosts file at `/etc/ansible/hosts.yml' with:

central.local

All I get is this error:

$ ansible all --list-hosts
[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'
  hosts (0):

Same thing when running the playbook.


Solution

  • The default path to the ansible inventory is /etc/ansible/hosts, not /etc/ansible/hosts.yml. You need to remove the file extension.

    You can also set a different path to the inventory file with the -i flag when running ansible.