Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic vars_files inclusion in chapter 5 'Playbook Variables' example broken #245

Closed
geerlingguy opened this issue Apr 22, 2020 · 2 comments
Closed

Comments

@geerlingguy
Copy link
Owner

@geerlingguy geerlingguy commented Apr 22, 2020

The way that vars_files are included probably changed somewhere in the Ansible 2.x lifecycle, rendering the example in the book a bit broken.

The playbook is:

---
- hosts: example
  vars_files:
    - "apache_default.yml"
    - "apache_{{ ansible_os_family }}.yml"
  tasks:
    - service: name={{ apache }} state=running

But that doesn't work.

Instead, we used include_vars in today's livestream, with with_first_found, which worked a bit better. I need to update that example in the book so it works correctly and doesn't mislead readers.

Also ansible_os_family is not CentOS, it's RedHat, on Cent OS (ansible_distribution is CentOS, however).

@geerlingguy
Copy link
Owner Author

@geerlingguy geerlingguy commented Apr 22, 2020

New example:

---
- hosts: example

  pre_tasks:
    - include_vars: "{{ item }}"
      with_first_found:
        - "apache_{{ ansible_os_family }}.yml"
        - "apache_default.yml"

  tasks:
    - name: Ensure Apache is running.
      service:
        name: "{{ apache_service_name }}"
        state: running

@geerlingguy
Copy link
Owner Author

@geerlingguy geerlingguy commented Apr 22, 2020

This has been fixed in the manuscript and will be in the next book release version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant