Giter Club home page Giter Club logo

ansible-module-check-structure's Introduction

ansible-module-check-structure

ansible-module-check-structure is a handy custom Ansible module allowing you assert the type of Ansible facts, and validate the structure (or schema) of dictionaries and lists.

This is done by crafting an Ansible fact in which each hierarcherical element is a string representing one of python's built-in types, apply this structure to a fact you want to check.

You may for instance want to check that each element of a list is a dictionary in which the foo key defined, and paired to a string value...

struct:
  - foo: str

... or check that each element of a list is an integer:

struct:
  - int

Possibilities are endless!

Getting started

Installing

The "Ansible role" way

  • Clone this repository to your Ansible role_path, or install via ansible-galaxy;

    ansible-galaxy install alexisfacques.ansible_module_check_structure
  • Import the role in your playbooks before running any role or task that require the check_structure module:

    - hosts: all
      roles:
        - alexisfacques.ansible_module_check_structure
      tasks:
        - name: Ensure variable is a string
          check_structure:
            struct:
              - str
            var:
              -"{{ is_this_a_str }}"

The "Ansible library" way

Alternatively, if importing a role is too much of a hassle, you can store this module in the library directory defined in your ansible.cfg file (Default is a sub-directory called library in the directory that contains your playbooks):

[defaults]
library = /path/to/your/library

Usage

Parameters

Parameter Choices/Defaults Comments
struct
- / required
The schema that the variable should validate.
var
- / required
The variable you want to test.

Example of use

Examples of use can be found here.

License

This project is licensed under the MIT License - see the LICENSE file for details.

ansible-module-check-structure's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.