Plugins

The assertions available are:

user_root

Determines if an user can become root or not.

If the user can become root true is returned, false is returned otherwise.

If the user is not defined or is empty, false is returned.

  - name: Test user_root with non-empty root.
    debug:
      msg: 'User can become root'
    failed_when: "not 'root' is user_root"

variable_boolean

Determines if a variable is of type boolean or not.

The values considered boolean are:

  • true
  • false
  • True
  • False
  • yes
  • no

If the variable is boolean, true is returned, false is returned otherwise.

  - name: Define boolean true variable.
    set_fact:
      boolean_true_var: true
  - name: Test variable_boolean with non-empty boolean false.
    debug:
      msg: 'Variable is boolean'
    failed_when: boolean_false_var is not variable_boolean

variable_boolean_true

Determines if a variable is of type boolean and if its value is true.

The values considered boolean are:

  • true
  • false
  • True
  • False
  • yes
  • no

If the variable is boolean and is set to true, a true value is returned, otherwise false is returned.

  - name: Define boolean false variable.
    set_fact:
      boolean_false_var: false
  - name: Test variable_boolean_true with non-empty boolean false.
    debug:
      msg: 'Variable is not boolean true'
    failed_when: boolean_false_var is variable_boolean_true

variable_collection

Determines if a variable is a collection or not.

If the variable is a collection, true is returned, false is returned otherwise.

  - name: Define non-empty collection variable.
    set_fact:
      non_empty_collection_var: [one, two]
  - name: Test variable_collection with non-empty collection.
    debug:
      msg: 'Variable is a collection'
    failed_when: non_empty_collection_var is not variable_collection

variable_empty

Determines if a variable is empty or not.

If the variable is empty, true is returned, false is returned otherwise.

  - name: Define non-empty variable.
    set_fact:
      non_empty_var: 'non-empty-value'
  - name: Test variable_empty with non-empty.
    debug:
      msg: 'Variable is not empty'
    failed_when: non_empty_var is variable_empty

variable_path

Determines if a variable is an existing path or not.

If the variable is an existing path, true is returned, false is returned otherwise.

  - name: Define path variable.
    set_fact:
      path_var: /bin/ls
  - name: Test variable_path with non-empty.
    debug:
      msg: 'Variable is a path'
    failed_when: path_var is not variable_path

variable_url

Determines if a variable is an URL or not.

If the variable is an URL, true is returned, false is returned otherwise.

  - name: Define non-existent url variable.
    set_fact:
      non_existent_url_var: https://constrict0r.readthedocs.io
  - name: Test variable_url with non-empty unexistent.
    debug:
      msg: 'Variable is URL'
    failed_when: non_existent_url_var is not variable_url

variable_url_existent

Determines if a variable is an existent URL or not.

If the variable is an existent URL, true is returned, false is returned otherwise.

For this test is recommendable to use URLs that points to single files and not to index or main sites, this to prevent non-200 status responses.

  - name: Define existent url variable.
    set_fact:
      existent_url_var: https://is.gd/AuuivH
  - name: Test variable_url_existent with non-empty existent.
    debug:
      msg: 'Variable is URL'
    failed_when: existent_url_var is not variable_url_existent