FTD configuration module: fix a bug with response parsing (#57480)

* Update dependence's name to firepower-kickstart

* Check response type before getting attributes

* Add unit test for construct_ansible_facts method

* Update error message
This commit is contained in:
Anton Nikulin 2019-06-10 16:00:36 +03:00 committed by Sumit Jaiswal
commit 4fa93d5b9b
5 changed files with 80 additions and 7 deletions

View file

@ -65,7 +65,7 @@ def construct_ansible_facts(response, params):
response_body = response['items'] if 'items' in response else response
if params.get('register_as'):
facts[params['register_as']] = response_body
elif response_body.get('name') and response_body.get('type'):
elif type(response_body) is dict and response_body.get('name') and response_body.get('type'):
object_name = re.sub(INVALID_IDENTIFIER_SYMBOLS, '_', response_body['name'].lower())
fact_name = '%s_%s' % (response_body['type'], object_name)
facts[fact_name] = response_body

View file

@ -29,8 +29,9 @@ except ImportError:
def assert_kick_is_installed(module):
if not HAS_KICK:
module.fail_json(msg='Firepower-kick library is required to run this module. '
'Please, install it with `pip install firepower-kick` command and run the playbook again.')
module.fail_json(msg='Firepower-kickstart library is required to run this module. '
'Please, install the library with `pip install firepower-kickstart` '
'command and run the playbook again.')
class FtdModel:

View file

@ -37,9 +37,9 @@ description:
the `local` connection should be used only when the device cannot be accessed via
REST API.
version_added: "2.8"
requirements: [ "python >= 3.5", "firepower-kick" ]
requirements: [ "python >= 3.5", "firepower-kickstart" ]
notes:
- Requires `firepower-kick` library that should be installed separately and requires Python >= 3.5.
- Requires `firepower-kickstart` library that should be installed separately and requires Python >= 3.5.
- On localhost, Ansible can be still run with Python >= 2.7, but the interpreter for this particular module must be
Python >= 3.5.
- Python interpreter for the module can overwritten in `ansible_python_interpreter` variable.