GithubHelp home page GithubHelp logo

ansible_variable_precedence's Introduction

Ansible Variable Precedence

This playbook demonstrates the many places that it is possible to assign variables in Ansible and the precedence rules that apply.

Precedence Rules

In order from highest to lowest:

  • Register Variables
  • Ansible assigned fact vars
  • Role Dependency Parameters
  • Vars file vars
  • Command line extra var
  • Playbook vars
  • Playbook Role parameter
  • Role var
  • Inventory Host variable
  • Inventory Group variable
  • Role default variable

Usage

To run the playbook, use the predefined script called bin/run_playbook. This defaults to using the -v flag so that the stdout of executed tasks is visible. Look for the stdout of the "THE MAIN EVENT echo echo echo" task to see which variable is currently active with the highest precedence. To demonstrate the rules in action, find the variable defined in the stdout of your most recent run of the playbook and go remove or comment out that specific assignment of the echo_var. Once you're done, if you rerun the playbook, you should see the next variable in the precedence order as the stdout for the task name mentioned above.

Prerequisites

  • Ansible v1.3
  • Ability to SSH into localhost without a password
  • ansible-playbook script available in Bash shell environment

v1.2 and earlier

To test the precedence rules against 1.2, simply change the required role in the playbook from dummy to precedence since v1.2 does not support role dependencies.

The predecedence list using this setup against Ansible v1.2 in order from highest to lowest:

  • Register Variables
  • Ansible assigned fact vars
  • Playbook Role parameter
  • Vars file vars
  • Role var
  • Command line extra var
  • Playbook vars
  • Inventory Host variable
  • Inventory Group variable

Versions prior to v1.2 were not tested.

Official Documentation

http://www.ansibleworks.com/docs/playbooks_variables.html

ansible_variable_precedence's People

Contributors

cookrn avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

spiette

ansible_variable_precedence's Issues

Different precedences on 1.9.3?

Hi there,
Looks like the precedence order again changed a bit, given the tests I've done thus far on MacOSX 10.10.x using ansible 1.9.3.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.