2

I do not wish to specify any hosts file to ansible-playbook command.

ansible-playbook site.yml  -e "source_host=mymac1 source_file=myfile1"

My site.yml looks like this:

more site.yml

---

- hosts: "{{ source_host | default('my_pc')}}"
  user: weblogic

However, I get the following error:

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

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

PLAYBOOK: site.yml ********************************************************************************************************************************************************************************** 2 plays in site.yml [WARNING]: Could not match supplied host pattern, ignoring: mymac1

Can you please suggest how can i pass any host to my playbook without having to maintain and host respository with all the host information

I am on ansible version 2.3.1.0

1 Answers1

4

You can use inline inventory:

playbook.yml:

- hosts: all
  tasks:
    - debug: msg=hello

command:

ansible-playbook -i 'mymac1,' -e source_file=myfile1 playbook.yml

note comma after hostname.

Also see: Ansible ad-hoc command with direct host specified - no hosts matched

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • I have two play inside my playbook so it has two -hosts: . How can i make sure the first - hosts: gets source_host=mymac1 and the second - hosts: gets dest_host=mymac2 which will be passed using the -e: ansible-playbook site.yml -e "source_host=mymac1 source_file=myfile1 dest_host=mymac2" – Know Your Tech Jan 31 '18 at 16:51
  • The first host will be the host of the source of the file while the second host will be the destination where it will be copied ... hence two hosts – Know Your Tech Jan 31 '18 at 17:01
  • Try `all[0]` and `all[1]` and `-i 'srchost,desthost'` (but I'm not sure, this is rather uncommon scenario). – Konstantin Suvorov Jan 31 '18 at 17:13