mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #7355/85e866cc backport][stable-7] newrelic_deployment: add app_name_exact_match parameter (#7367)
newrelic_deployment: add app_name_exact_match parameter (#7355)
* newrelic_deployment: add app_name_exact_match parameter
* add changelog
* fix ident
* fix line ending format
* Update plugins/modules/newrelic_deployment.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update changelogs/fragments/7355-newrelic-deployment-add-exact-name.yml
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/modules/newrelic_deployment.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/modules/newrelic_deployment.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/modules/newrelic_deployment.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/modules/newrelic_deployment.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Write out abbreviation.
---------
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 85e866ccdd
)
Co-authored-by: matiasba <matiasabarros@hotmail.com>
This commit is contained in:
parent
00efbe6ea2
commit
c1309ceb8b
2 changed files with 24 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- "newrelic_deployment - add option ``app_name_exact_match``, which filters results for the exact app_name provided (https://github.com/ansible-collections/community.general/pull/7355)."
|
|
@ -68,6 +68,14 @@ options:
|
|||
required: false
|
||||
default: true
|
||||
type: bool
|
||||
app_name_exact_match:
|
||||
type: bool
|
||||
description:
|
||||
- If this flag is set to V(true) then the application ID lookup by name would only work for an exact match.
|
||||
If set to V(false) it returns the first result.
|
||||
required: false
|
||||
default: false
|
||||
version_added: 7.5.0
|
||||
requirements: []
|
||||
'''
|
||||
|
||||
|
@ -102,8 +110,10 @@ def main():
|
|||
revision=dict(required=True),
|
||||
user=dict(required=False),
|
||||
validate_certs=dict(default=True, type='bool'),
|
||||
app_name_exact_match=dict(required=False, type='bool', default=False),
|
||||
),
|
||||
required_one_of=[['app_name', 'application_id']],
|
||||
required_if=[('app_name_exact_match', True, ['app_name'])],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
|
@ -111,7 +121,6 @@ def main():
|
|||
params = {}
|
||||
if module.params["app_name"] and module.params["application_id"]:
|
||||
module.fail_json(msg="only one of 'app_name' or 'application_id' can be set")
|
||||
|
||||
app_id = None
|
||||
if module.params["app_name"]:
|
||||
app_id = get_application_id(module)
|
||||
|
@ -150,6 +159,7 @@ def main():
|
|||
def get_application_id(module):
|
||||
url = "https://api.newrelic.com/v2/applications.json"
|
||||
data = "filter[name]=%s" % module.params["app_name"]
|
||||
application_id = None
|
||||
headers = {
|
||||
'Api-Key': module.params["token"],
|
||||
}
|
||||
|
@ -161,7 +171,17 @@ def get_application_id(module):
|
|||
if result is None or len(result.get("applications", "")) == 0:
|
||||
module.fail_json(msg='No application found with name "%s"' % module.params["app_name"])
|
||||
|
||||
return result["applications"][0]["id"]
|
||||
if module.params["app_name_exact_match"]:
|
||||
for item in result["applications"]:
|
||||
if item["name"] == module.params["app_name"]:
|
||||
application_id = item["id"]
|
||||
break
|
||||
if application_id is None:
|
||||
module.fail_json(msg='No application found with exact name "%s"' % module.params["app_name"])
|
||||
else:
|
||||
application_id = result["applications"][0]["id"]
|
||||
|
||||
return application_id
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue