2014-09-26 01:01:01 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2012 Dag Wieers <dag@wieers.com>
|
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 05:55:24 +00:00
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-03-14 16:07:22 +00:00
|
|
|
'status': ['stableinterface'],
|
|
|
|
'supported_by': 'core'}
|
|
|
|
|
2016-12-06 10:35:05 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: assert
|
2017-01-27 23:20:31 +00:00
|
|
|
short_description: Asserts given expressions are true
|
2014-09-26 01:01:01 +00:00
|
|
|
description:
|
2016-09-20 15:51:57 +00:00
|
|
|
- This module asserts that given expressions are true with an optional custom message.
|
2017-06-26 15:26:53 +00:00
|
|
|
- This module is also supported for Windows targets.
|
2014-09-26 01:01:01 +00:00
|
|
|
version_added: "1.5"
|
|
|
|
options:
|
|
|
|
that:
|
|
|
|
description:
|
|
|
|
- "A string expression of the same form that can be passed to the 'when' statement"
|
|
|
|
- "Alternatively, a list of string expressions"
|
|
|
|
required: true
|
2018-06-14 17:35:15 +00:00
|
|
|
fail_msg:
|
2018-06-14 20:56:48 +00:00
|
|
|
version_added: "2.7"
|
2016-09-20 15:51:57 +00:00
|
|
|
description:
|
|
|
|
- "The customized message used for a failing assertion"
|
2018-06-18 18:01:08 +00:00
|
|
|
- "This argument was called 'msg' before version 2.7, now it's renamed to 'fail_msg' with alias 'msg'"
|
2018-06-14 17:35:15 +00:00
|
|
|
aliases:
|
|
|
|
- msg
|
2018-06-14 15:34:04 +00:00
|
|
|
success_msg:
|
|
|
|
version_added: "2.7"
|
|
|
|
description:
|
|
|
|
- "The customized message used for a successful assertion"
|
2017-06-26 15:26:53 +00:00
|
|
|
notes:
|
|
|
|
- This module is also supported for Windows targets.
|
2017-01-27 23:20:31 +00:00
|
|
|
author:
|
2015-06-15 19:53:30 +00:00
|
|
|
- "Ansible Core Team"
|
|
|
|
- "Michael DeHaan"
|
2014-09-26 01:01:01 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
- assert: { that: "ansible_os_family != 'RedHat'" }
|
|
|
|
|
2017-01-27 23:20:31 +00:00
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "'foo' in some_command_result.stdout"
|
2014-09-26 01:01:01 +00:00
|
|
|
- "number_of_the_counting == 3"
|
2016-09-20 15:51:57 +00:00
|
|
|
|
2018-06-18 19:01:38 +00:00
|
|
|
- name: after version 2.7 both 'msg' and 'fail_msg' can customize failing assertion message
|
|
|
|
assert:
|
2017-01-27 23:20:31 +00:00
|
|
|
that:
|
2016-09-20 15:51:57 +00:00
|
|
|
- "my_param <= 100"
|
|
|
|
- "my_param >= 0"
|
2018-06-14 17:35:15 +00:00
|
|
|
fail_msg: "'my_param' must be between 0 and 100"
|
2018-06-14 15:34:04 +00:00
|
|
|
success_msg: "'my_param' is between 0 and 100"
|
2018-06-18 18:01:08 +00:00
|
|
|
|
2018-06-18 19:01:38 +00:00
|
|
|
- name: please use 'msg' when ansible version is smaller than 2.7
|
|
|
|
assert:
|
2018-06-18 18:01:08 +00:00
|
|
|
that:
|
|
|
|
- "my_param <= 100"
|
|
|
|
- "my_param >= 0"
|
|
|
|
msg: "'my_param' must be between 0 and 100"
|
2014-09-26 01:01:01 +00:00
|
|
|
'''
|