Having issues using a variable in a playbook

23 views
Skip to first unread message

Benjamin Arntzen

unread,
Jan 13, 2015, 7:15:49 PM1/13/15
to ansible...@googlegroups.com
Hi there,

I'm trying to build python 3.4.2 in a semi-idempotent way. I see mpdehaan's comments on it and didn't have any issues following those.

The issue I'm having is that the variables defined in common.yml aren't being carried through to the second play (python-app-server). I would like to simply define vars_files in the first play and have it carry forward. Am I just thinking about it wrong?

Here's my playbook's site.yml file, as I would like it to look:
---
# file: site.yml
- hosts: all
  user
: '{{ deploy_user }}'
  sudo
: yes
  vars_files
:
   
- vars/common.yml
   
- [ "vars/{{ ansible_os_family }}.yml", "vars/os_defaults.yml" ]


  roles
:
   
- base
   
- redacted-base


- hosts: python-app-server
  user
: '{{ deploy_user }}'
  roles
:
   
- python-app-server

And here's how it has to look in order to work at the moment:

---
# file: site.yml
- hosts: all
  user
: '{{ deploy_user }}'
  sudo
: yes
  vars_files
:
   
- vars/common.yml
   
- [ "vars/{{ ansible_os_family }}.yml", "vars/os_defaults.yml" ]


  roles
:
   
- base
   
- redacted-base


- hosts: python-app-server
  user
: '{{ deploy_user }}'
  vars_files
:
   
- vars/common.yml
  roles
:
   
- python-app-server

I'm totally unconcerned about adding two lines, I just want a much cleaner way to express this. Thoughts?

Thanks,
~ B

Tom Bamford

unread,
Jan 13, 2015, 10:02:56 PM1/13/15
to ansible...@googlegroups.com
Hi Benjamin

Look at specifying variables using group_vars or host_vars (see http://docs.ansible.com/intro_inventory.html#splitting-out-host-and-group-specific-data)

There is a special group 'all' of which all hosts are automatically a member.

Regards
Tom


--
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.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b015d643-17f6-4298-8c5e-64a5e32804d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Jan 14, 2015, 7:57:44 AM1/14/15
to ansible...@googlegroups.com
vars/vars_files/registered vars are in the single play scope, if you
want common.yml vars present in other plays you need to import it
there also.



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages