Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing host information when running ansible playbook

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?

like image 589
ali haider Avatar asked Jul 08 '16 16:07

ali haider


People also ask

How do I find my host on Ansible?

You can use the option --list-hosts. It will show all the host IPs from your inventory file.

How do you handle an unreachable host in Ansible?

Resetting unreachable hosts If Ansible cannot connect to a host, it marks that host as 'UNREACHABLE' and removes it from the list of active hosts for the run. You can use meta: clear_host_errors to reactivate all hosts, so subsequent tasks can try to reach them again.

How does Ansible connect to host?

By default, Ansible connects to all remote devices with the user name you are using on the control node. If that user name does not exist on a remote device, you can set a different user name for the connection. If you just need to do some tasks as a different user, look at Understanding privilege escalation: become.


1 Answers

-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
like image 85
udondan Avatar answered Sep 23 '22 13:09

udondan