-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: kksat <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,117 additions
and
148 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -24,7 +24,7 @@ namespace: sap | |
|
||
name: sap_operations | ||
|
||
version: 2.2.0 | ||
version: 2.4.0 | ||
|
||
readme: README.md | ||
|
||
|
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,84 @@ | ||
#!/usr/bin/python | ||
|
||
# SPDX-License-Identifier: GPL-3.0-only | ||
# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere | ||
# | ||
# Copyright 2024 Red Hat, Project Atmosphere | ||
# | ||
# 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, version 3 of the License. | ||
# | ||
# 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. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# You should have received a copy of the GNU General Public License along with this program. | ||
# If not, see <https://www.gnu.org/licenses/>. | ||
|
||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
DOCUMENTATION = """ | ||
--- | ||
module: is_container | ||
extends_documentation_fragment: sap.sap_operations.community | ||
author: Kirill Satarin (@kksat) | ||
short_description: Determine if the current host is a container | ||
description: | ||
- Determine if the current host is a container | ||
- Two methods are used to determine if the current host is a container | ||
- The C(systemd-detect-virt) command is used to detect if the host is a container | ||
- The C(/.dockerenv) and C(/run/.containerenv) files are checked to see if they exist | ||
version_added: 2.4.0 | ||
options: {} | ||
""" | ||
|
||
EXAMPLES = """ | ||
--- | ||
- name: Are we running in a container? | ||
sap.sap_operations.is_container: | ||
""" | ||
|
||
RETURN = """ | ||
--- | ||
is_container: | ||
description: Whether the current host is a container | ||
returned: success | ||
type: bool | ||
""" | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
import os | ||
|
||
|
||
def main(): | ||
module = AnsibleModule(argument_spec=dict(), supports_check_mode=True) | ||
|
||
is_container = False | ||
try: | ||
rc, stdout, stderr = module.run_command( | ||
"systemd-detect-virt", | ||
check_rc=False, | ||
handle_exceptions=False, | ||
) | ||
is_container = is_container or (rc == 0 and "container" in stdout) | ||
except Exception: | ||
pass | ||
|
||
is_container = is_container or ( | ||
os.path.exists("/.dockerenv") or os.path.exists("/run/.containerenv") | ||
) | ||
|
||
module.exit_json(is_container=is_container) | ||
|
||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# SPDX-License-Identifier: GPL-3.0-only | ||
# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere | ||
# | ||
# Copyright 2024 Red Hat, Project Atmosphere | ||
# | ||
# 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, version 3 of the License. | ||
# | ||
# 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. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# You should have received a copy of the GNU General Public License along with this program. | ||
# If not, see <https://www.gnu.org/licenses/>. | ||
|
||
--- | ||
DOCUMENTATION: | ||
name: app_instance | ||
author: Kirill Satarin (@kksat) | ||
extends_documentation_fragment: sap.sap_operations.community | ||
version_added: 2.3.0 | ||
short_description: Test to check if the provided sap instance is SAP application instance. | ||
description: | ||
- Test to check if the provided sap instance is SAP application instance. | ||
- This test filter is expected to be used with combination of sap.sap_operations.host_info module | ||
- Type of instance is determined by processes this instance runs (ProcessList value) | ||
options: | ||
value: | ||
description: One of the instances, returned by sap.sap_operations.host_info | ||
required: true | ||
seealso: | ||
- module: sap.sap_operations.host_info | ||
|
||
EXAMPLES: | | ||
- name: Get all sap instances | ||
sap.sap_operations.host_info: | ||
become: true | ||
become_user: root | ||
register: host_info | ||
- name: Filter only SAP APP instances | ||
ansible.builtin.debug: | ||
msg: "{{ host_info.instances | select('sap.sap_operations.app_instance') }}" | ||
RETURN: | ||
_value: | ||
type: boolean | ||
description: True if instance is SAP APP instance | ||
example: true |
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,55 @@ | ||
# SPDX-License-Identifier: GPL-3.0-only | ||
# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere | ||
# | ||
# Copyright 2024 Red Hat, Project Atmosphere | ||
# | ||
# 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, version 3 of the License. | ||
# | ||
# 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. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# You should have received a copy of the GNU General Public License along with this program. | ||
# If not, see <https://www.gnu.org/licenses/>. | ||
|
||
--- | ||
DOCUMENTATION: | ||
name: ascs_instance | ||
author: Kirill Satarin (@kksat) | ||
extends_documentation_fragment: sap.sap_operations.community | ||
version_added: 2.3.0 | ||
short_description: Test to check if the provided sap instance is SAP ASCS instance. | ||
description: | ||
- Test to check if the provided sap instance is SAP ASCS instance. | ||
- This test filter is expected to be used with combination of sap.sap_operations.host_info module | ||
- Type of instance is determined by processes this instance runs (ProcessList value) | ||
options: | ||
value: | ||
description: One of the instances, returned by sap.sap_operations.host_info | ||
required: true | ||
seealso: | ||
- module: sap.sap_operations.host_info | ||
|
||
EXAMPLES: | | ||
- name: Get all sap instances | ||
sap.sap_operations.host_info: | ||
become: true | ||
become_user: root | ||
register: host_info | ||
- name: Filter only SAP ASCS instances | ||
ansible.builtin.debug: | ||
msg: "{{ host_info.instances | select('sap.sap_operations.ascs_instance') }}" | ||
RETURN: | ||
_value: | ||
type: boolean | ||
description: True if instance is SAP ASCS instance | ||
example: true |
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,55 @@ | ||
# SPDX-License-Identifier: GPL-3.0-only | ||
# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere | ||
# | ||
# Copyright 2024 Red Hat, Project Atmosphere | ||
# | ||
# 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, version 3 of the License. | ||
# | ||
# 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. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# You should have received a copy of the GNU General Public License along with this program. | ||
# If not, see <https://www.gnu.org/licenses/>. | ||
|
||
--- | ||
DOCUMENTATION: | ||
name: hana_instance | ||
author: Kirill Satarin (@kksat) | ||
extends_documentation_fragment: sap.sap_operations.community | ||
version_added: 2.3.0 | ||
short_description: Test to check if the provided sap instance is SAP HANA instance. | ||
description: | ||
- Test to check if the provided sap instance is SAP HANA instance. | ||
- This test filter is expected to be used with combination of sap.sap_operations.host_info module | ||
- Type of instance is determined by processes this instance runs (ProcessList value) | ||
options: | ||
value: | ||
description: One of the instances, returned by sap.sap_operations.host_info | ||
required: true | ||
seealso: | ||
- module: sap.sap_operations.host_info | ||
|
||
EXAMPLES: | | ||
- name: Get all sap instances | ||
sap.sap_operations.host_info: | ||
become: true | ||
become_user: root | ||
register: host_info | ||
- name: Filter only SAP HANA instances | ||
ansible.builtin.debug: | ||
msg: "{{ host_info.instances | select('sap.sap_operations.hana_instance') }}" | ||
RETURN: | ||
_value: | ||
type: boolean | ||
description: True if instance is SAP HANA instance | ||
example: true |
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,55 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# SPDX-License-Identifier: GPL-3.0-only | ||
# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere | ||
# | ||
# Copyright 2024 Red Hat, Project Atmosphere | ||
# | ||
# 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, version 3 of the License. | ||
# | ||
# 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. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# You should have received a copy of the GNU General Public License along with this program. | ||
# If not, see <https://www.gnu.org/licenses/>. | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
__metaclass__ = type | ||
|
||
|
||
def sap_instance(name: str, description: str): | ||
def f(instance): | ||
try: | ||
return any( | ||
instance_process["name"] == name | ||
and instance_process["description"] == description | ||
for instance_process in instance["ProcessList"] | ||
) | ||
except KeyError: | ||
return False | ||
|
||
return f | ||
|
||
|
||
def ascs_instance(instance): | ||
return sap_instance(name="enserver", description="EnqueueServer")( | ||
instance | ||
) and sap_instance(name="msg_server", description="MessageServer")(instance) | ||
|
||
|
||
class TestModule(object): | ||
def tests(self): | ||
return { | ||
"hana_instance": sap_instance(name="hdbdaemon", description="HDB Daemon"), | ||
"app_instance": sap_instance(name="disp+work", description="Dispatcher"), | ||
"ascs_instance": ascs_instance, | ||
} |
Oops, something went wrong.