Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding requirements to be able to use as a role #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,39 @@ The following modules are available with the corresponding actions:
debug:
msg: "{{ okta_saml_app.json }}"
```


#### Jira Search Module

Still in beta

Missing Proper Issue Array and field custom or native field capability

The default filter in jira is 4 and stand for all open issues

The filter can be changed depending on the saved seach

The filter id appears in at the en of the link when a search result is selected https://jira/browse/EXAM?filter=4


```
- name: Get Jira Issue
jira_search:
uri: "{{ domain }}"
username: "{{ username }}"
password: "{{ password }}"
register: issue

- name: Get Jira Issue
jira_search:
uri: "{{ domain }}"
username: "{{ username }}"
password: "{{ password }}"
filter: 4
register: issue

- name: Print Jira Issues
debug:
msg: "{{ item.fields }}"
with_items: "{{ issue.jira.issues }}"
```
136 changes: 136 additions & 0 deletions library/jira_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/python
# (c) 2019, Whitney Champion <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'}

DOCUMENTATION = """
module: jira_search
short_description: Communicate with jira to provide issue searching capabality
description:
- Search Jira API for issues
version_added: "1.0"
author: "Adam Corriveau (@livemonkey1300)"
options:
uri:
description:
- domain of the compagny
required: true
default: None
username:
description:
- Username having permission to the current filter
required: true
default: None
password:
description:
- Password of the current user for jira api access
required: true
default: None
filter:
description:
- The filter id to the issue search
required: false
default: 4
"""

EXAMPLES = '''
# Get Jira Issue
- name: Get Jira Issue
jira_search:
uri: "{{ domain }}"
username: "{{ username }}"
password: "{{ password }}"
register: issue

# Get Jira Issue using a specific filter
- name: Get Jira Issue
jira_search:
uri: "{{ domain }}"
username: "{{ username }}"
password: "{{ password }}"
filter: 4
register: issue

# Example of the issues output
- name: Print Jira Issues
debug:
msg: "{{ item.fields }}"
with_items: "{{ issue.jira.issues }}"
'''

RETURN = r'''
jira:
description: Return Jira Issues
returned: always
type: complex
msg:
description: Return if theire was an issues
returned: always
type: str
sample: OK (unknown bytes)
changed:
description: Return change depending on success
returned: always
type: int
sample: 200
'''

import base64
import json
import sys
import requests
from ansible.module_utils._text import to_text, to_bytes

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url



class JiraSearch:
def __init__(self, host , username , password , filter=4):
self.host = "https://" + host + "/"
self.username = username
self.password = password
self.auth = base64.b64encode('{0}:{1}'.format(self.username, self.password))
self.filter = filter

def connect_jira(self , query='search?filter='):
url = '%s%s%s%s' % ( self.host , "rest/api/2/" , query , self.filter )
headers = { "Accept": "application/json","Authorization": "Basic %s" % self.auth }
response = requests.request("GET",url,headers=headers)
return response

def get_jira_result(self):
response = self.connect_jira()
return json.loads(response.text)

def main():
global module
module = AnsibleModule(
argument_spec = dict(
uri= dict(required=True),
username=dict(required=True),
password=dict(required=True, no_log=True),
filter=dict(type='int', default=4),
)
)
uri = module.params['uri']
user = module.params['username']
passwd = module.params['password']
filter = module.params['filter']

try:
jira_con = JiraSearch( uri , user , passwd , filter ).get_jira_result()

except Exception as e:
return module.fail_json(changed=False , msg=e.message)

module.exit_json(changed=True, jira=dict(jira_con))



if __name__ == '__main__':
main()
13 changes: 13 additions & 0 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,16 @@
organization: "{{ organization }}"
api_key: "{{ api_key }}"
id: "{{ okta_user.json.id }}"

- name: Get Jira Issue
jira_search:
uri: "{{ domain }}"
username: "{{ username }}"
password: "{{ password }}"
filter: 4
register: issue

- name: Print Jira Issues
debug:
msg: "{{ item.fields }}"
with_items: "{{ issue.jira.issues }}"
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---