Bug 1485074 - [RFE]: Add conditional or remove include_vars within role as include_vars is too high on variable precedence
Summary: [RFE]: Add conditional or remove include_vars within role as include_vars is ...
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: rhel-system-roles
Version: 7.4
Hardware: Unspecified
OS: Linux
Target Milestone: rc
: ---
Assignee: Thomas Haller
QA Contact: qe-baseos-daemons
Depends On:
TreeView+ depends on / blocked
Reported: 2017-08-24 23:32 UTC by jamarsha
Modified: 2020-12-14 09:42 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed: 2017-10-19 15:21:00 UTC
Target Upstream Version:

Attachments (Terms of Use)
Replication playbook example (209 bytes, text/x-vhdl)
2017-08-24 23:32 UTC, jamarsha
no flags Details

System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2017:2970 0 normal SHIPPED_LIVE rhel-system-roles bug fix update 2017-10-19 18:54:31 UTC

Description jamarsha 2017-08-24 23:32:39 UTC
Created attachment 1317934 [details]
Replication playbook example

Description of problem:
The include_vars module is too high on the variable precedence list as documented here: http://docs.ansible.com/ansible/latest/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable and significantly prevents user customization. Users are unable to define variables for the role at the top level playbook and can only overwrite with extra vars or facts.

Version-Release number of selected component (if applicable):

How reproducible:
Top level playbook which calls the network role attached.

Steps to Reproduce:
1. `ansible-playbook -i some_inventory network-var.yml -e nodes="some_group_or_host"`

Actual results:
At the role "tasks" level, the following task overwrites "something_else" for network_provider

- name: Set version specific variables
  include_vars: "{{ item }}"
      - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
      - "{{ ansible_distribution }}.yml"
      - "{{ ansible_os_family }}.yml"
      - "default.yml"

Expected results:
"something_else" is retained

Additional info:
This is important for network role users on RHEL7 who are still using initscripts over NetworkManager. The only way around this requires custom modification of the role and should be more accessible.

Comment 3 Pavel Cahyna 2017-09-12 16:24:53 UTC
I can't really reproduce your problem with network_provider. If I set it to "something_else", the role complains that "unsupported provider something_else". IMO this is correct. Yes, include_vars module is high on the variable precedence list, but the files included this way do not actually define "network_provider" and therefore they do not clobber it. It clobbers network_provider_default and network_packages, but I suppose those are not intended to be customized by the user.

To debug such issues, I suggest importing the role using tasks:include_role: instead of roles: and use the debug module before and after. You should see that the network role changes network_provider_default but not network_provider.

    - name: debug var before
        var: network_provider
    - name: net role
        name: linux-system-roles.network
      ignore_errors: True
    - name: debug var after
        var: network_provider

Comment 8 Thomas Haller 2017-09-21 09:23:15 UTC
the files in vars [1] do not define "network_provider" at all. Hence, the original comment is incorrect:

> At the role "tasks" level, the following task overwrites "something_else" for 
> network_provider

Which can also be seen with -vvvv:

  fatal: [test-server]: FAILED! => {
      "changed": false, 
      "failed": true, 
      "invocation": {
          "module_args": {
              "connections": [
              "ignore_errors": "False", 
              "provider": "initscripts"

What however happens is that other variables like network_service_name and network_packages are overwritten. Which is wrong and needs fixing

[1] https://github.com/linux-system-roles/network/tree/a4ebfadded1c4e96e3a7b5e71f7cfc2da46ee1d6/vars

Comment 9 Thomas Haller 2017-09-21 10:51:16 UTC
Please review https://github.com/linux-system-roles/network/pull/14

Comment 16 errata-xmlrpc 2017-10-19 15:21:00 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


Note You need to log in before you can comment on or make changes to this bug.