Skip to content

Commit

Permalink
add status_info module
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Sep 21, 2020
1 parent 830b5c7 commit 42b66c8
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 0 deletions.
76 changes: 76 additions & 0 deletions plugins/modules/status_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2020 Evgeni Golov
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import absolute_import, division, print_function
__metaclass__ = type


DOCUMENTATION = '''
---
module: status_info
version_added: 1.3.0
short_description: Get status info
description:
- Get status information from the server
author:
- "Evgeni Golov (@evgeni)"
extends_documentation_fragment:
- theforeman.foreman.foreman
'''

EXAMPLES = '''
- name: status
theforeman.foreman.status:
server_url: "https://foreman.example.com"
username: "admin"
password: "changeme"
'''

RETURN = '''
status:
description: Basic status of the server.
returned: always
type: dict
ping:
description: Detailed service status.
returned: if supported by server
type: dict
'''

from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import ForemanAnsibleModule


def main():
module = ForemanAnsibleModule()

with module.api_connection():
status = module.status()

if 'ping' in module.foremanapi.resources:
if 'ping' in module.foremanapi.resource('ping').actions:
ping_action = 'ping'
else:
ping_action = 'index'
ping = module.foremanapi.resource('ping').call(ping_action)
else:
ping = None

module.exit_json(status=status, ping=ping)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
'setting',
'smart_class_parameter',
'snapshot',
'status_info',
'subnet',
'sync_plan',
'templates_import',
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/apidoc/status_info.json
170 changes: 170 additions & 0 deletions tests/test_playbooks/fixtures/status_info-0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json;version=2
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- apypie (https://github.com/Apipie/apypie)
method: GET
uri: https://foreman.example.org/api/status
response:
body:
string: '{"result":"ok","status":200,"version":"2.1.2","api_version":2}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
style-src ''unsafe-inline'' ''self'''
Content-Type:
- application/json; charset=utf-8
Foreman_api_version:
- '2'
Foreman_current_location:
- ; ANY
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.1.2
Keep-Alive:
- timeout=15, max=100
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- sameorigin
X-Permitted-Cross-Domain-Policies:
- none
X-XSS-Protection:
- 1; mode=block
content-length:
- '62'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json;version=2
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- apypie (https://github.com/Apipie/apypie)
method: GET
uri: https://foreman.example.org/api/status
response:
body:
string: '{"result":"ok","status":200,"version":"2.1.2","api_version":2}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
style-src ''unsafe-inline'' ''self'''
Content-Type:
- application/json; charset=utf-8
Foreman_api_version:
- '2'
Foreman_current_location:
- ; ANY
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.1.2
Keep-Alive:
- timeout=15, max=99
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- sameorigin
X-Permitted-Cross-Domain-Policies:
- none
X-XSS-Protection:
- 1; mode=block
content-length:
- '62'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json;version=2
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- apypie (https://github.com/Apipie/apypie)
method: GET
uri: https://foreman.example.org/api/ping
response:
body:
string: '{"results":{"foreman":{"database":{"active":true,"duration_ms":"0"}}}}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
style-src ''unsafe-inline'' ''self'''
Content-Type:
- application/json; charset=utf-8
Foreman_api_version:
- '2'
Foreman_current_location:
- ; ANY
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.1.2
Keep-Alive:
- timeout=15, max=98
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- sameorigin
X-Permitted-Cross-Domain-Policies:
- none
X-XSS-Protection:
- 1; mode=block
content-length:
- '70'
status:
code: 200
message: OK
version: 1
20 changes: 20 additions & 0 deletions tests/test_playbooks/status_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- hosts: localhost
collections:
- theforeman.foreman
gather_facts: false
vars_files:
- vars/server.yml
tasks:
- name: fetch status
include_tasks: tasks/status_info.yml

- hosts: tests
collections:
- theforeman.foreman
gather_facts: false
vars_files:
- vars/server.yml
tasks:
- name: fetch status
include_tasks: tasks/status_info.yml
7 changes: 7 additions & 0 deletions tests/test_playbooks/tasks/status_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: fetch status
status_info:
username: "{{ foreman_username }}"
password: "{{ foreman_password }}"
server_url: "{{ foreman_server_url }}"
validate_certs: "{{ foreman_validate_certs }}"

0 comments on commit 42b66c8

Please sign in to comment.