Software Engineering

Learn how to Go Variables to Ansible Playbook CLI

Learn how to Go Variables to Ansible Playbook CLI
Written by admin


If you must go a variable to Ansible playbook, utilizing the command line, then you are able to do the next:

Possibility 1 – Specifying command line arguments

ansible-playbook launch.yml --extra-vars "model=1.23.45 other_variable=foo"

N.B. --extra-vars specified variables will override any variables with the identical title outlined contained in the playbook.

You can even learn up on Passing Variables On The Command Line (Wayback Machine hyperlink to take care of versioning)

Possibility 2 – Specify a YML file

You can even specify a .yml file with the variables:

vars:
    my_version: "{{ model }}"
    my_other_variable: {{ other_variable }}

This may also be enhanced with setting variables:

vars:
    my_version: "{{ lookup('env', 'model') }}"
    my_other_variable: {{ lookup('env', 'other_variable') }}

About the author

admin

Leave a Comment