title: Ansible playbook only add role dependency variables
body: <p>All files is </p>
  
  <pre><code># roles/a/defaults/main.yml
  test: Role A
  
  # roles/a/tasks/main.yml
  - name: Things I dont want to run
    debug: msg="Not expected"
  
  
  # hosts
  host-1 host-1 ansible_connection=local test=Override
  
  
  # test.yml
  - hosts: all
    roles:
      - a # I only need the variable
    tasks:
      - name: action
        debug: var=test # Expected Override
  </code></pre>
  
  <p>How can I do this ?</p>
  
  <p>I thought about this</p>
  
  <pre><code>roles/
      a-var # only include defaults variable definition
      a # depends on a-var
      b # depends on a-var, but do not run role a's task
  </code></pre>
  
  <p>Kind of cumbersome,but I think this might the only way to work around.</p>
  
  <p>Why I want this is I don't want the user care about too many files (<code>group_vars,host_vars,extra_vars</code>) ,and they don't know ansible,I have to deploy our system as easy as possible, the only thing they need to care about is inventory files,like this</p>
  
  <pre><code>host-1
  host-2
  
  [a]
  host-1 port=1234
  
  [b]
  host-2 # use default port defined in role
  
  [all:vars]
  install_path=/opt # override the default path
  </code></pre>
  
  <p>But the order to load variable is </p>
  
  <ul>
  <li>role defaults</li>
  <li>inventory vars</li>
  <li>inventory group_vars</li>
  <li>inventory host_vars</li>
  <li>playbook group_vars</li>
  <li>playbook host_vars</li>
  <li>host facts</li>
  <li>registered vars</li>
  <li>set_facts</li>
  <li>play vars</li>
  <li>play vars_prompt</li>
  <li>play vars_files</li>
  <li>role and include vars</li>
  <li>block vars (only for tasks in block)</li>
  <li>task vars (only for the task)</li>
  <li>extra vars (always win precedence)</li>
  </ul>
  
  <p>this is hard for this organize,because I can't do this,var files will beat inventory config. </p>
  
  <pre><code>- host: b
    var_files:
      # I hope this is just default and not take over inventory config
      - roles/a/defaults/main.yml 
    tasks:
      - debug: var=install_path # become default not custom's
  </code></pre>