Skip to content

Commit

Permalink
Import OS-specific variables in common role
Browse files Browse the repository at this point in the history
We've relied on ansible's ability to use host-based facts to include
variables for quite some time. This functionality is apparently not
supported and has been silently failing for a while now. If you run
your playbooks with -vvvv you will see messages like:

skipping vars_file 'vars/{{ ansible_os_family }}.yml' due to an undefined variable

The solution seems to be to move these includes to an include_vars
task inside the role. The "always" tag means it always runs.

See: ansible/ansible#28024
  • Loading branch information
alanorth committed Nov 19, 2017
1 parent e24b1d9 commit 489e1c2
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 12 deletions.
2 changes: 0 additions & 2 deletions compute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
become: yes
remote_user: provisioning
vars_files:
- "vars/{{ ansible_os_family }}.yml"
- private/vars/common.yml
- "private/vars/{{ ansible_os_family }}.yml"
- private/vars/ipsets.yml
roles:
- common
Expand Down
2 changes: 0 additions & 2 deletions dspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
become: yes
remote_user: provisioning
vars_files:
- "vars/{{ ansible_os_family }}.yml"
- private/vars/common.yml
- private/vars/dspace.yml
- "private/vars/{{ ansible_os_family }}.yml"
- private/vars/ipsets.yml
roles:
- common
Expand Down
2 changes: 0 additions & 2 deletions nomads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
become: yes
remote_user: provisioning
vars_files:
- "vars/{{ ansible_os_family }}.yml"
- private/vars/common.yml
- "private/vars/{{ ansible_os_family }}.yml"
- private/vars/ipsets.yml
roles:
- common
Expand Down
6 changes: 6 additions & 0 deletions roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---
- name: Import OS-specific variables
include_vars: "{{ item }}"
with_items:
- "vars/{{ ansible_os_family }}.yml"
- "private/vars/{{ ansible_os_family }}.yml"
tags: always

- name: Install common packages
import_tasks: packages.yml
Expand Down
2 changes: 0 additions & 2 deletions solr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
become: yes
remote_user: provisioning
vars_files:
- "vars/{{ ansible_os_family }}.yml"
- private/vars/common.yml
- "private/vars/{{ ansible_os_family }}.yml"
- private/vars/ipsets.yml
roles:
- common
Expand Down
2 changes: 0 additions & 2 deletions storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
become: yes
remote_user: provisioning
vars_files:
- "vars/{{ ansible_os_family }}.yml"
- private/vars/common.yml
- "private/vars/{{ ansible_os_family }}.yml"
- private/vars/ipsets.yml
roles:
- common
Expand Down
2 changes: 0 additions & 2 deletions web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
become: yes
remote_user: provisioning
vars_files:
- "vars/{{ ansible_os_family }}.yml"
- private/vars/common.yml
- "private/vars/{{ ansible_os_family }}.yml"
- private/vars/ipsets.yml
roles:
- common
Expand Down

0 comments on commit 489e1c2

Please sign in to comment.