Reputation: 397
I have a directory where I created ansible.cfg, inventory_win and windesk.yml(my playbook). In ansible.cfg I defined the following
[defaults]
host_key_checking=False
ansible_python_interpreter= /usr/bin/python3
hostfile = inventory_win
Inside inventory_win I have
myfirsthost ansible_host=192.168.10.30
my2ndthost2 ansible_host=192.168.10.34
[windesk]
myfirsthost
my2ndthost2
[datacenter:children]
windesk
In windesk.yml, I have
---
- hosts: windesk
vars:
ansible_site_path: "c:\\inetpub\\wwwroot\\some\\"
vsite: "Default Web Site"
vsiteindexfile: "index3.html"
tasks:
- name: create new website's directory
win_file: path={{ ansible_site_path }} state=directory
- name: Create a virtual directory if it does not exist
win_iis_virtualdirectory:
name: somedirectroy
site: "{{ vsite }}"
state: present
physical_path: "{{ ansible_site_path }}"
When I run
ansible-playbook windesk.yaml
I get
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' [WARNING]: Could not match supplied host pattern, ignoring: windesk
PLAY [windesk] ******************************************************************************************** skipping: no hosts matched
PLAY RECAP
but running
ansible-playbook -i inventory_win windesk.yaml
it works fine and I get the expected results
Upvotes: 0
Views: 3117
Reputation: 11992
Your definition in the ansible.cfg
is incorrect. The docs detail that the key name should be inventory
not hostfile
Description Comma separated list of Ansible inventory sources
Type pathlist
Default /etc/ansible/hosts
Ini Section [defaults]
Key inventory
[defaults]
host_key_checking = False
ansible_python_interpreter =/ usr/bin/python3
inventory = inventory_win
OUTPUT
[centos@vps-f116ed9f stack_ansible]$ ansible-playbook windesk.yml -vvv
ansible-playbook 2.9.27
config file = /home/centos/stack_ansible/ansible.cfg
configured module search path = [u'/home/centos/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Jun 28 2022, 15:30:04) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
Using /home/centos/stack_ansible/ansible.cfg as config file
host_list declined parsing /home/centos/stack_ansible/inventory_win as it did not pass its verify_file() method
script declined parsing /home/centos/stack_ansible/inventory_win as it did not pass its verify_file() method
auto declined parsing /home/centos/stack_ansible/inventory_win as it did not pass its verify_file() method
Parsed /home/centos/stack_ansible/inventory_win inventory source with ini plugin
Upvotes: 2