Skip to content

Commit

Permalink
Release galaxy-2.4.0
Browse files Browse the repository at this point in the history
Signed-off-by: kksat <[email protected]>
  • Loading branch information
kksat committed Oct 18, 2024
1 parent 43a7c19 commit bdd281f
Show file tree
Hide file tree
Showing 17 changed files with 1,117 additions and 148 deletions.
326 changes: 179 additions & 147 deletions docs/CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace: sap

name: sap_operations

version: 2.2.0
version: 2.4.0

readme: README.md

Expand Down
84 changes: 84 additions & 0 deletions plugins/modules/is_container.py
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()
55 changes: 55 additions & 0 deletions plugins/test/app_instance.yml
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
55 changes: 55 additions & 0 deletions plugins/test/ascs_instance.yml
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
55 changes: 55 additions & 0 deletions plugins/test/hana_instance.yml
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
55 changes: 55 additions & 0 deletions plugins/test/sap_instances.py
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,
}
Loading

0 comments on commit bdd281f

Please sign in to comment.