Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple ansible command meets "ERROR: The file hosts is marked as executable"

Tags:

ansible

new to ansible.

I installed ansible in ubuntu vm 14.04.1 version using ppa installation

user@ubuntu:~$ ansible --version
ansible 1.7

And created the hosts file with localhost only

user@ubuntu:~$ cat hosts
localhost

When I try to run this simple command

user@ubuntu:~$ ansible -i hosts all -m ping --ask-pass
SSH password:
ERROR: The file hosts is marked as executable, but failed to execute correctly. If this is not supposed to be an executable script, correct this with `chmod -x hosts`.

UPDATE when I follow the instruction to remove the execution mode for hosts file, it works.

But the message is still quite strange for me, why need execute hosts file.

What's wrong with this ?

like image 728
Larry Cai Avatar asked Aug 23 '14 04:08

Larry Cai


1 Answers

There are a few types of files that can be passed to ansible with the -i option.

  1. Inventory files - a single ini formated inventory file
  2. A script that returns dynamic inventory as json
  3. A directory that contains a combination of (1) and (2)

In your case Ansible assumed that because you had the executable bit set on the file hosts that it was a dynamic inventory executable.

It's very common to use a dynamic inventory file (2) for situations where you need to discover the ip addresses of the hosts that you want to work on. One example is the case where you need to query a directory service of some sort or maybe an API to get a list of hosts that are grouped on the fly.

like image 156
jarv Avatar answered Sep 20 '22 09:09

jarv