Last active
August 31, 2023 20:15
-
-
Save zeitounator/d7987d8a58ba6f48da3e417a31fd28ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ansible --version | |
ansible [core 2.15.2] | |
config file = None | |
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] | |
ansible python module location = /home/user/.local/lib/python3.10/site-packages/ansible | |
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections | |
executable location = /home/user/.local/bin/ansible | |
python version = 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (/usr/bin/python) | |
jinja version = 3.1.2 | |
libyaml = True | |
$ cat test.yml | |
- hosts: localhost | |
gather_facts: false | |
vars: | |
page_info: | |
{ | |
"cache_control": "no-store", | |
"changed": false, | |
"connection": "close", | |
"content_type": "application/json", | |
"cookies": { | |
"JSESSIONID": "6EBC3322C3AC46B647F07D95600FA2CE" | |
}, | |
"cookies_string": "JSESSIONID=6EBC3322C3AC46B647F07D95600FA2CE", | |
"date": "Thu, 31 Aug 2023 01:07:43 GMT", | |
"elapsed": 1, | |
"expires": "Thu, 01 Jan 1970 00:00:00 GMT", | |
"failed": false, | |
"json": { | |
"_expandable": { | |
"ancestors": "", | |
"body": "", | |
"container": "/rest/api/space/MyConfluenceSpace", | |
"descendants": "/rest/api/content/123456789/descendant", | |
"history": "/rest/api/content/123456789/history", | |
"metadata": "", | |
"operations": "", | |
"restrictions": "/rest/api/content/123456789/restriction/byOperation", | |
"space": "/rest/api/space/MyConfluenceSpace", | |
"version": "" | |
}, | |
"_links": { | |
"base": "https://my.url.com/confluence", | |
"collection": "/rest/api/content", | |
"context": "/confluence", | |
"edit": "/pages/resumedraft.action?draftId=123456789", | |
"self": "https://my.url.com/confluence/rest/api/content/123456789", | |
"tinyui": "/x/eJWsIQ", | |
"webui": "/pages/viewpage.action?pageId=123456789" | |
}, | |
"children": { | |
"_expandable": { | |
"comment": "/rest/api/content/123456789/child/comment", | |
"page": "/rest/api/content/123456789/child/page" | |
}, | |
"_links": { | |
"self": "https://my.url.com/confluence/rest/api/content/123456789/child" | |
}, | |
"attachment": { | |
"_links": { | |
"self": "https://my.url.com/confluence/rest/api/content/123456789/child/attachment" | |
}, | |
"limit": 25, | |
"results": [ | |
{ | |
"_expandable": { | |
"ancestors": "", | |
"body": "", | |
"children": "/rest/api/content/123456789/child", | |
"container": "/rest/api/content/123456789", | |
"descendants": "/rest/api/content/123456789/descendant", | |
"history": "/rest/api/content/123456789/history", | |
"operations": "", | |
"restrictions": "/rest/api/content/123456789/restriction/byOperation", | |
"space": "/rest/api/space/MyConfluenceSpace", | |
"version": "" | |
}, | |
"_links": { | |
"download": "/download/attachments/123456789/otherfile1.xls?version=1&modificationDate=1693436900349&api=v2", | |
"self": "https://my.url.com/confluence/rest/api/content/123456789", | |
"webui": "/pages/viewpage.action?pageId=123456789&preview=%2F564958584%2F564958591%2Fotherfile1.xls" | |
}, | |
"extensions": { | |
"comment": "File attached via Ansible Automation Platform", | |
"fileSize": 519168, | |
"mediaType": "application/vnd.ms-excel" | |
}, | |
"id": "123456789", | |
"metadata": { | |
"comment": "File attached via Ansible Automation Platform", | |
"mediaType": "application/vnd.ms-excel" | |
}, | |
"status": "current", | |
"title": "otherfile1.xls", | |
"type": "attachment" | |
}, | |
{ | |
"_expandable": { | |
"ancestors": "", | |
"body": "", | |
"children": "/rest/api/content/123456789/child", | |
"container": "/rest/api/content/123456789", | |
"descendants": "/rest/api/content/123456789/descendant", | |
"history": "/rest/api/content/123456789/history", | |
"operations": "", | |
"restrictions": "/rest/api/content/123456789/restriction/byOperation", | |
"space": "/rest/api/space/MyConfluenceSpace", | |
"version": "" | |
}, | |
"_links": { | |
"download": "/download/attachments/123456789/otherfile2.xlsx?version=1&modificationDate=1693436878967&api=v2", | |
"self": "https://my.url.com/confluence/rest/api/content/123456789", | |
"webui": "/pages/viewpage.action?pageId=123456789&preview=%2F564958584%2F564958590%2Fotherfile2.xlsx" | |
}, | |
"extensions": { | |
"comment": "File attached via Ansible Automation Platform", | |
"fileSize": 957067, | |
"mediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | |
}, | |
"id": "123456789", | |
"metadata": { | |
"comment": "File attached via Ansible Automation Platform", | |
"mediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | |
}, | |
"status": "current", | |
"title": "otherfile2.xlsx", | |
"type": "attachment" | |
}, | |
{ | |
"_expandable": { | |
"ancestors": "", | |
"body": "", | |
"children": "/rest/api/content/123456789/child", | |
"container": "/rest/api/content/123456789", | |
"descendants": "/rest/api/content/123456789/descendant", | |
"history": "/rest/api/content/123456789/history", | |
"operations": "", | |
"restrictions": "/rest/api/content/123456789/restriction/byOperation", | |
"space": "/rest/api/space/MyConfluenceSpace", | |
"version": "" | |
}, | |
"_links": { | |
"download": "/download/attachments/123456789/otherfile3.xlsx?version=1&modificationDate=1693436872870&api=v2", | |
"self": "https://my.url.com/confluence/rest/api/content/123456789", | |
"webui": "/pages/viewpage.action?pageId=123456789&preview=%2F564958584%2F564958589%2Fotherfile3.xlsx" | |
}, | |
"extensions": { | |
"comment": "File attached via Ansible Automation Platform", | |
"fileSize": 957067, | |
"mediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | |
}, | |
"id": "123456789", | |
"metadata": { | |
"comment": "File attached via Ansible Automation Platform", | |
"mediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | |
}, | |
"status": "current", | |
"title": "otherfile3.xlsx", | |
"type": "attachment" | |
}, | |
{ | |
"_expandable": { | |
"ancestors": "", | |
"body": "", | |
"children": "/rest/api/content/123456789/child", | |
"container": "/rest/api/content/123456789", | |
"descendants": "/rest/api/content/123456789/descendant", | |
"history": "/rest/api/content/123456789/history", | |
"operations": "", | |
"restrictions": "/rest/api/content/123456789/restriction/byOperation", | |
"space": "/rest/api/space/MyConfluenceSpace", | |
"version": "" | |
}, | |
"_links": { | |
"download": "/download/attachments/123456789/myFile.xml?version=1&modificationDate=1693436842746&api=v2", | |
"self": "https://my.url.com/confluence/rest/api/content/123456789", | |
"webui": "/pages/viewpage.action?pageId=123456789&preview=%2F564958584%2F564958587%2FmyFile.xml" | |
}, | |
"extensions": { | |
"comment": "File attached via Ansible Automation Platform", | |
"fileSize": 6665740, | |
"mediaType": "application/xml" | |
}, | |
"id": "123456789", | |
"metadata": { | |
"comment": "File attached via Ansible Automation Platform", | |
"mediaType": "application/xml" | |
}, | |
"status": "current", | |
"title": "myFile.xml", | |
"type": "attachment" | |
} | |
], | |
"size": 4, | |
"start": 0 | |
} | |
}, | |
"extensions": { | |
"position": 71 | |
}, | |
"id": "123456789", | |
"status": "current", | |
"title": "My Page Title", | |
"type": "page" | |
}, | |
"msg": "OK (unknown bytes)", | |
"redirected": false, | |
"server": "Apache", | |
"set_cookie": "JSESSIONID=6EBC3322C3AC46B647F07D95600FA2CE; Path=/confluence; HttpOnly", | |
"status": 200, | |
"transfer_encoding": "chunked", | |
"url": "https://my.url.com/confluence/rest/api/content/123456789?expand=children.attachment", | |
"x_ausername": "myUsername", | |
"x_content_type_options": "nosniff", | |
"x_seraph_loginreason": "OK" | |
} | |
tasks: | |
- debug: | |
var: page_info.json.children.attachment.results | selectattr("title", "equalto", "myFile.xml") | map(attribute="_links.download") | join("") | |
- set_fact: | |
file_url: '{{ page_info.json.children.attachment.results | selectattr("title", "equalto", "myFile.xml") | map(attribute="_links.download") | join("") }}' | |
- debug: | |
var: file_url | |
$ ansible-playbook test.yml | |
PLAY [localhost] ******************************************************************************************************************************************************************************************************************* | |
TASK [debug] *********************************************************************************************************************************************************************************************************************** | |
ok: [localhost] => { | |
"page_info.json.children.attachment.results | selectattr(\"title\", \"equalto\", \"myFile.xml\") | map(attribute=\"_links.download\") | join(\"\")": "/download/attachments/129975585/myFile.xml?version=1&modificationDate=1693436842746&api=v2" | |
} | |
TASK [set_fact] ******************************************************************************************************************************************************************************************************************** | |
ok: [localhost] | |
TASK [debug] *********************************************************************************************************************************************************************************************************************** | |
ok: [localhost] => { | |
"file_url": "/download/attachments/129975585/myFile.xml?version=1&modificationDate=1693436842746&api=v2" | |
} | |
PLAY RECAP ************************************************************************************************************************************************************************************************************************* | |
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment