On 18/04/16 13:37, fanvalt wrote:
Hello,

I would like to set a lot of parameters when playing my playbook,
depending on the server/user where it will be deployed so the idea is to
set it in the hosts file.

It doesn't seem to work as my varaibles are no set, here is what I plan
to do:

[webserver]
linuxserv ansible_connection=local ansible_user=aa12
extra-vars="@/home/root/vars/vars.json"

running the playbook this way:
  ansible-playbook deploy.yml

and with vars.json:

{
   "ENVT": "aa12",
   "MODULE": "tomweb",
   "RELEASE": "1.2",
}

Is this possible or do I have to try to load the vars parameter file in
the playbook ?
If the variables are host specific as you first indicate, you can use host variables or group variables
You need to have the specific directory structure :
- hosts (file)
- host_vars/ (directory)
- group_vars/ (directory)

$ cat hosts
[webserver]
linuxserv

$ cat host_vars/linuxserv
---
ansible_connection: local
ansible_user: aa12
ENVT: aa12
MODULE: tomweb
RELEASE: 1.2

$ cat group_vars/webserver
---
webserver: apache

Now you run the playbook with those hosts and the variables will be usable from each hosts You can actually have different inventory names and different actual names using this
You can group hosts and use group_vars directory
The host file is an ini file (or executable), while the host and group vars file are json/yaml files (that is why they have the three dashes)

For more info look at the documentation, it is very clearly explained :
http://docs.ansible.com/ansible/intro_inventory.html

--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5714D831.60803%40vantosh.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to