I have an ansbile.cfg file as well as a host file in a directory. In the same directory, I have a test_playbook.yml file. All three are copied below. When I run the ping (ad-hoc) command, I get a successful response. However, when I try running the ansible-playbook command, the response states the following:
[WARNING]: Host file not found: testserver
[WARNING]: provided hosts list is empty, only localhost is available
skipping: no hosts matched
ansible.cfg
[defaults]
hostfile = hosts
remote_user = testuser
##private_key_file = .vagrant/machines/default/virtualbox/private_key
##host_key_checking = False
hosts
[webservers]
testserver ansible_ssh_host=ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com ansible_ssh_port=1234
test_playbook.yml
---
- hosts: all
remote_user: testuser
become: yes
become_user: testuser
tasks:
- group:
name: devops
state: present
- name: create devops user with admin privileges
user:
name: devops
comment: "Devops User"
uid: 2001
groups: devops
The command that I am running is the following:
ansible-playbook test_playbook.yml -i testserver -vvv
response:
Any idea on what I might have misconfigured?
-i
specifies your inventory file, not the host. So it should be -i hosts
.
ansible-playbook test_playbook.yml -i hosts
You also can directly pass the host, but then you won't have the behavioral host vars as defined in the inventory file:
ansible-playbook test_playbook.yml -i testserver,
The ,
makes ansible treat it as a list of hosts, otherwise it will treat it as a filename.
If you want to limit it to the host testserver
you can work with the --limit
option
ansible-playbook test_playbook.yml -i hosts --limit testserver