Bhargav Mg
Bhargav Mg

Reputation: 337

unable to connect to a remote server through ansible playbook

I'm quite new to ansible and i have a new problem recently. I try to run the playbook and below is the error i get.

[bhar1@desktop ~]$ ansible-playbook -i inv abc.yaml -vvv
ansible-playbook 2.4.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/bhar1/.ansible/plugins                       /modules', u'/usr/share/ansible/plugins/modules']
 ansible python module location = /usr/lib/python2.7/site-packages                                                                                                                                                                            /ansible
 executable location = /bin/ansible-playbook
 python version = 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5          20150623 (Red Hat 4.8.5-28)]
Using /etc/ansible/ansible.cfg as config file
[WARNING]: Unable to parse /home/bhar1/inv as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is  available

[WARNING]: Could not match supplied host pattern, ignoring: all

 [WARNING]: provided hosts list is empty, only localhost is available


 PLAYBOOK: abc.yaml    **********************************************************************************************************************************
 1 plays in abc.yaml
 [WARNING]: Could not match supplied host pattern, ignoring: webservers


  PLAY [webservers]  ***********************************************************************************************************************************
 skipping: no hosts matched

 PLAY RECAP ******************************************************************************************************************************************

Can you please help me explain what could be the reason for this. My /etc/ansible/hosts file is updates with webservers group as we. Below is the yml file.

[bhar1@desktop ~]$ cat abc.yaml 
---
- hosts: webservers
  become: yes
  tasks:
  - name: remove httpd
    yum:
      name: httpd
      state: absent
[bhar1@desktop ~]$ 

Upvotes: 1

Views: 1786

Answers (3)

Tiya Jose
Tiya Jose

Reputation: 1419

Error is displayed because Ansible is unable to find your inventory file.

To execute the playbook abc.yaml, run the following command:

ansible-playbook -i /etc/ansible/hosts abc.yaml

Execution tells the ansible to use inventory file available in /etc/ansible/hosts and to parse playbook file "abc.yaml".Inventory argument -i is used to pass the inventory path.

Upvotes: 1

Debugger
Debugger

Reputation: 532

If you have updated the host group in /etc/ansible/hosts , you need to pass the path with -i, you have passed wrong file as i see its empty , use below and see if it works

ansible-playbook -i /etc/ansible/hosts abc.yaml 

Upvotes: 2

AviadP.
AviadP.

Reputation: 1

it seems that ansible looking for wrong inventory file. does this file "/home/bhar1/inv" exist? if not, then you should use:

    ansible-playbook -i [/path/to/inventory_file] abc.yaml -vvv

Upvotes: 0

Related Questions