Re: [ansible-project] How to specify host file via playbook?

23,808 views
Skip to first unread message

benno joy

unread,
Mar 20, 2013, 10:54:40 AM3/20/13
to ansible...@googlegroups.com
Hi Samnang,

You can use ansible-playbook -i hosts abc.yml to specify your inventory file.

you can also have a look at https://github.com/ansible/ansible-examples for some examples.






On Wed, Mar 20, 2013 at 5:43 PM, Samnang Sen <samna...@gmail.com> wrote:
By default it will read from /etc/ansible/hosts, but how can I specify the location of this file if I'm creating a playbook?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Brian Coca

unread,
Mar 20, 2013, 11:08:29 AM3/20/13
to ansible...@googlegroups.com
I actually use a shebang on my playbooks

#!/usr/bin/env ansible-playbook -i ../hosts

--
Brian Coca
Stultorum infinitus est numerus
0110000101110010011001010110111000100111011101000010000001111001011011110111010100100000011100110110110101100001011100100111010000100001
Pedo mellon a minno

Michael DeHaan

unread,
Mar 20, 2013, 11:15:06 AM3/20/13
to ansible...@googlegroups.com
All good answers -- also never thought of that, Brian!

FYI -- It's also configurable in /etc/ansible/ansible.cfg or ~/.ansible.cfg
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Timothy Gerla

unread,
Mar 20, 2013, 11:28:30 AM3/20/13
to ansible...@googlegroups.com
And finally, you can set the ANSIBLE_HOSTS shell variable:

export ANSIBLE_HOSTS=/home/ansible/my-hosts
ansible-playbook site.yml

-Tim
Tim Gerla
t...@gerla.net

Marco Vito Moscaritolo

unread,
Mar 20, 2013, 12:22:53 PM3/20/13
to ansible...@googlegroups.com
I also use PROJECT_FOLDER/ansible.cfg

[defaults]
hostfile = ./etc/hosts
remote_tmp = $HOME/.ansible/tmp
pattern = *
forks=5
timeout=10
transport=ssh
remote_port=112233
remote_user=xxxxxx

[ssh_connection]
ssh_args=-o PasswordAuthentication=no -o ControlMaster=auto -o
ControlPersist=60s -o ControlPath=/tmp/ansible-ssh-%h-%p-%r
scp_if_ssh=True
Ciao
Marco
--
web: http://mavimo.org
msn: mav...@tiscali.it
gtalk: mav...@gmail.com
mob: +39 393 9249923
skype: marco.moscaritolo
twitter: http://twitter.com/mavimo

anatoly techtonik

unread,
Dec 1, 2013, 6:44:03 AM12/1/13
to ansible...@googlegroups.com
On Wednesday, March 20, 2013 7:22:53 PM UTC+3, Mavimo wrote:
I also use PROJECT_FOLDER/ansible.cfg

[defaults]
hostfile = ./etc/hosts

anatoly techtonik

unread,
Dec 1, 2013, 12:53:18 PM12/1/13
to ansible...@googlegroups.com

It appears that look up from playbook's directory is broken. The command above will
point to hosts file from the current directory and not from playbook's dir. I filled an issue here:
https://github.com/ansible/ansible/issues/5115

Michael DeHaan

unread,
Dec 1, 2013, 12:55:07 PM12/1/13
to ansible...@googlegroups.com
We will look into docs but it works correctly.

-- Michael
--

anatoly techtonik

unread,
Dec 1, 2013, 1:07:52 PM12/1/13
to ansible...@googlegroups.com
I prefer if it worked as described in docs - independent of current user position
in directory tree hierarchy. I execute ansible playbooks using relative paths, from
different dirs, and if my current dir will happen to contain ansible.cfg from another
project - this may lead to disaster. For me reading configuration pieces implicitly
from CWD  is an anti-pattern.

Michael DeHaan

unread,
Dec 1, 2013, 1:16:46 PM12/1/13
to ansible...@googlegroups.com
Don't do that then :)

-- Michael

anatoly techtonik

unread,
Dec 1, 2013, 2:45:06 PM12/1/13
to ansible...@googlegroups.com
To be honest, the main usercase is to avoid typing `-i hosts` every time for bootstrap
of config from github checkout. There is only one localhost and if I can just place
ansible.cfg in repository together with playbook - it will solve all my problems. =)

  git clone myworkstation /tmp/a
  ansible-playbook /tmp/a/playbook.yml
Reply all
Reply to author
Forward
0 new messages