Introduction to Ansible Part ④'Variable'

About variables

Basic variables

vars In Ansible, basically, variables are placed in the vars section as follows.

vars


vars:
  Name: tanaka
  age: 25
  city: tokyo

register By using the register clause when starting the module, the value of the result based on the result of the task can be saved in the variable. Also, if the variable contains a dictionary, {{result.hogehoge}} or It can be referred to as {{result ['hogegoge']}}.

register


  - name test
    command: --------
    register: result

debug If you want to display variables, use debug module.

debug


  - debug: msg="result:{{result.hogehoge}}"

Fact

When Ansible executes a playbook, a process called GATHERING FACTS is performed before executing the first task. This refers to the information that Ansible has stored in variables with details about the host such as CPU architecture, OS and IP address. These can be used like any other function. The Official Documentation (http://bit.ly/1G9pVfx) has a partial list of available facts.

Built-in variables

Ansible defines the following variables for use in playbooks at any time.

hostvars A dictionary that uses the Ansible host name as the key and the variable name and value mapping as the value.

inventory_hostname The name of the current host that Ansible knows

group_names List of all groups of which the current host is a member

groups A dictionary whose key is the Ansible group name and whose value is a list of host names of the members of that group.

play_hosts The host name and host of the inventory that is active in the current play.


** References ** First Ansible (written by Lorin Hochstein, translated by Ryuji Tamagawa, O'Reilly Japan Co., Ltd.)

Recommended Posts

Introduction to Ansible Part ④'Variable'
Introduction to Ansible Part 1'Hello World !!'
Introduction to Python Hands On Part 1
Introduction to MQTT (Introduction)
Introduction to Scrapy (1)
Introduction to Scrapy (3)
Introduction to Supervisor
Introduction to Tkinter 1: Introduction
Introduction to PyQt
Introduction to Scrapy (2)
[Linux] Introduction to Linux
Introduction to Scrapy (4)
Introduction to discord.py (2)
[Introduction to Udemy Python3 + Application] 8. Variable declaration
Introduction to discord.py
Kaggle: Introduction to Manual Feature Engineering Part 1
[Introduction to cx_Oracle] (Part 3) Basics of Table Reference
[Introduction to cx_Oracle] (Part 7) Handling of bind variables
Introduction to Web Scraping
Introduction to Nonparametric Bayes
Introduction to Python language
Introduction to TensorFlow-Image Recognition
Introduction to OpenCV (python)-(2)
Introduction to Dependency Injection
Introduction to Private Chainer
[Introduction to cx_Oracle] (Part 11) Basics of PL / SQL Execution
[Introduction to cx_Oracle] (Part 13) Connection using connection pool (client side)
AOJ Introduction to Programming Topic # 1, Topic # 2, Topic # 3, Topic # 4
Introduction to electronic paper modules
A quick introduction to pytest-mock
Introduction to dictionary lookup algorithm
[Introduction to cx_Oracle] (Part 6) DB and Python data type mapping
[Learning memorandum] Introduction to vim
Introduction to PyTorch (1) Automatic differentiation
opencv-python Introduction to image processing
Introduction to Python Django (2) Win
Kubernetes Scheduler Introduction to Homebrew
An introduction to machine learning
[Introduction to cx_Oracle] Overview of cx_Oracle
Part 1 Attempt to code mathematics (∈)
[Introduction to pytorch-lightning] First Lit ♬
[Introduction to cx_Oracle] (Part 4) Fetch and scroll of result set
Introduction to Anomaly Detection 1 Basics
[Introduction to Systre] Fibonacci Retracement ♬
Introduction to Nonlinear Optimization (I)
An introduction to Python that even monkeys can understand (Part 3)
AOJ Introduction to Programming Topic # 5, Topic # 6
Introduction to Deep Learning ~ Learning Rules ~
[Introduction to Python] <list> [edit: 2020/02/22]
Machine learning to learn with Nogizaka46 and Keyakizaka46 Part 1 Introduction
Introduction to Python (Python version APG4b)
An introduction to Python Programming
Introduction to Python scikit-learn, matplotlib, single-layer algorithm (~ towards B3 ~ part3)
[Introduction to cx_Oracle] (8th) cx_Oracle 8.0 release
An introduction to Bayesian optimization
Deep Reinforcement Learning 1 Introduction to Reinforcement Learning
An introduction to Python that even monkeys can understand (Part 1)
Super introduction to machine learning
Series: Introduction to cx_Oracle Contents
An introduction to Python that even monkeys can understand (Part 2)
[Introduction] How to use open3d