summaryrefslogtreecommitdiff
path: root/plugins/modules/vyos_banner.py
diff options
context:
space:
mode:
authorBradley A. Thornton <bthornto@thethorntons.net>2019-08-09 10:48:27 -0700
committerBradley A. Thornton <bthornto@thethorntons.net>2019-08-09 10:48:27 -0700
commit5fb9df4e907a6ab2da7a6c2dafdec9c1971e8d44 (patch)
tree4459ed61d06c8d8caabbcc3ab36d84e27a919ee7 /plugins/modules/vyos_banner.py
parent7b9a33a29007ed302c3001566061e22c514cde64 (diff)
downloadvyos.vyos-5fb9df4e907a6ab2da7a6c2dafdec9c1971e8d44.tar.gz
vyos.vyos-5fb9df4e907a6ab2da7a6c2dafdec9c1971e8d44.zip
bt_blackked
Diffstat (limited to 'plugins/modules/vyos_banner.py')
-rw-r--r--plugins/modules/vyos_banner.py93
1 files changed, 48 insertions, 45 deletions
diff --git a/plugins/modules/vyos_banner.py b/plugins/modules/vyos_banner.py
index 7f070994..67386247 100644
--- a/plugins/modules/vyos_banner.py
+++ b/plugins/modules/vyos_banner.py
@@ -20,9 +20,9 @@
#
ANSIBLE_METADATA = {
- 'metadata_version': '1.1',
- 'status': ['preview'],
- 'supported_by': 'network'
+ "metadata_version": "1.1",
+ "status": ["preview"],
+ "supported_by": "network",
}
DOCUMENTATION = """
@@ -88,30 +88,33 @@ commands:
import re
from ansible.module_utils.basic import AnsibleModule
-from ansible_collections.vyos.vyos.plugins.module_utils.network. \
- vyos.vyos import get_config, load_config
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
+ get_config,
+ load_config,
+)
-from ansible_collections.vyos.vyos.plugins.module_utils.network. \
- vyos.vyos import vyos_argument_spec
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
+ vyos_argument_spec,
+)
def spec_to_commands(updates, module):
commands = list()
want, have = updates
- state = module.params['state']
-
- if state == 'absent':
- if have.get('state') != 'absent' or (have.get('state') != 'absent'
- and 'text' in have.keys()
- and have['text']):
- commands.append('delete system login banner %s' %
- module.params['banner'])
-
- elif state == 'present':
- if want['text'] and want['text'].encode().decode(
- 'unicode_escape') != have.get('text'):
- banner_cmd = 'set system login banner %s ' % module.params['banner']
- banner_cmd += want['text'].strip()
+ state = module.params["state"]
+
+ if state == "absent":
+ if have.get("state") != "absent" or (
+ have.get("state") != "absent" and "text" in have.keys() and have["text"]
+ ):
+ commands.append("delete system login banner %s" % module.params["banner"])
+
+ elif state == "present":
+ if want["text"] and want["text"].encode().decode("unicode_escape") != have.get(
+ "text"
+ ):
+ banner_cmd = "set system login banner %s " % module.params["banner"]
+ banner_cmd += want["text"].strip()
commands.append(banner_cmd)
return commands
@@ -120,67 +123,67 @@ def spec_to_commands(updates, module):
def config_to_dict(module):
data = get_config(module)
output = None
- obj = {'banner': module.params['banner'], 'state': 'absent'}
+ obj = {"banner": module.params["banner"], "state": "absent"}
- for line in data.split('\n'):
- if line.startswith('set system login banner %s' % obj['banner']):
- match = re.findall(r'%s (.*)' % obj['banner'], line, re.M)
+ for line in data.split("\n"):
+ if line.startswith("set system login banner %s" % obj["banner"]):
+ match = re.findall(r"%s (.*)" % obj["banner"], line, re.M)
output = match
if output:
- obj['text'] = output[0].encode().decode('unicode_escape')
- obj['state'] = 'present'
+ obj["text"] = output[0].encode().decode("unicode_escape")
+ obj["state"] = "present"
return obj
def map_params_to_obj(module):
- text = module.params['text']
+ text = module.params["text"]
if text:
text = "%r" % (str(text).strip())
return {
- 'banner': module.params['banner'],
- 'text': text,
- 'state': module.params['state']
+ "banner": module.params["banner"],
+ "text": text,
+ "state": module.params["state"],
}
def main():
""" main entry point for module execution
"""
- argument_spec = dict(banner=dict(required=True,
- choices=['pre-login', 'post-login']),
- text=dict(),
- state=dict(default='present',
- choices=['present', 'absent']))
+ argument_spec = dict(
+ banner=dict(required=True, choices=["pre-login", "post-login"]),
+ text=dict(),
+ state=dict(default="present", choices=["present", "absent"]),
+ )
argument_spec.update(vyos_argument_spec)
- required_if = [('state', 'present', ('text', ))]
+ required_if = [("state", "present", ("text",))]
- module = AnsibleModule(argument_spec=argument_spec,
- required_if=required_if,
- supports_check_mode=True)
+ module = AnsibleModule(
+ argument_spec=argument_spec, required_if=required_if, supports_check_mode=True
+ )
warnings = list()
- result = {'changed': False}
+ result = {"changed": False}
if warnings:
- result['warnings'] = warnings
+ result["warnings"] = warnings
want = map_params_to_obj(module)
have = config_to_dict(module)
commands = spec_to_commands((want, have), module)
- result['commands'] = commands
+ result["commands"] = commands
if commands:
commit = not module.check_mode
load_config(module, commands, commit=commit)
- result['changed'] = True
+ result["changed"] = True
module.exit_json(**result)
-if __name__ == '__main__':
+if __name__ == "__main__":
main()