forked from theforeman/foreman-ansible-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
275 additions
and
0 deletions.
There are no files selected for viewing
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
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() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foreman.json |
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
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 |
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
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 |
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
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 }}" |