summaryrefslogtreecommitdiffstats
path: root/ansible_collections/ngine_io/exoscale
diff options
context:
space:
mode:
Diffstat (limited to 'ansible_collections/ngine_io/exoscale')
-rw-r--r--ansible_collections/ngine_io/exoscale/.github/dependabot.yml8
-rw-r--r--ansible_collections/ngine_io/exoscale/.github/workflows/publish.yml35
-rw-r--r--ansible_collections/ngine_io/exoscale/.github/workflows/sanity.yml45
-rw-r--r--ansible_collections/ngine_io/exoscale/CHANGELOG.rst8
-rw-r--r--ansible_collections/ngine_io/exoscale/FILES.json92
-rw-r--r--ansible_collections/ngine_io/exoscale/MANIFEST.json8
-rw-r--r--ansible_collections/ngine_io/exoscale/README.md3
-rw-r--r--ansible_collections/ngine_io/exoscale/changelogs/changelog.yaml6
-rw-r--r--ansible_collections/ngine_io/exoscale/plugins/doc_fragments/exoscale.py3
-rw-r--r--ansible_collections/ngine_io/exoscale/plugins/module_utils/exoscale.py7
-rw-r--r--ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_domain.py5
-rw-r--r--ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_record.py6
-rw-r--r--ansible_collections/ngine_io/exoscale/plugins/modules/instance_rdns_record.py186
13 files changed, 329 insertions, 83 deletions
diff --git a/ansible_collections/ngine_io/exoscale/.github/dependabot.yml b/ansible_collections/ngine_io/exoscale/.github/dependabot.yml
new file mode 100644
index 000000000..607e7e1a2
--- /dev/null
+++ b/ansible_collections/ngine_io/exoscale/.github/dependabot.yml
@@ -0,0 +1,8 @@
+# Set update schedule for GitHub Actions
+---
+version: 2
+updates:
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ schedule:
+ interval: "weekly"
diff --git a/ansible_collections/ngine_io/exoscale/.github/workflows/publish.yml b/ansible_collections/ngine_io/exoscale/.github/workflows/publish.yml
index 0318edfc4..2bcd079fe 100644
--- a/ansible_collections/ngine_io/exoscale/.github/workflows/publish.yml
+++ b/ansible_collections/ngine_io/exoscale/.github/workflows/publish.yml
@@ -7,19 +7,24 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
+ defaults:
+ run:
+ working-directory: ansible_collections/ngine_io/exoscale
steps:
- - uses: actions/checkout@v1
- - name: Set up Python
- uses: actions/setup-python@v1
- with:
- python-version: '3.x'
- - name: Install dependencies
- run: |
- python -m pip install --upgrade pip
- pip install ansible
- - name: Build and publish
- env:
- ANSIBLE_GALAXY_API_KEY: ${{ secrets.ANSIBLE_GALAXY_API_KEY }}
- run: |
- ansible-galaxy collection build .
- ansible-galaxy collection publish *.tar.gz --api-key $ANSIBLE_GALAXY_API_KEY
+ - uses: actions/checkout@v3
+ with:
+ path: ansible_collections/ngine_io/exoscale
+ - name: Set up Python
+ uses: actions/setup-python@v4
+ with:
+ python-version: "3.x"
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install ansible
+ - name: Build and publish
+ env:
+ ANSIBLE_GALAXY_API_KEY: ${{ secrets.ANSIBLE_GALAXY_API_KEY }}
+ run: |
+ ansible-galaxy collection build .
+ ansible-galaxy collection publish *.tar.gz --api-key $ANSIBLE_GALAXY_API_KEY
diff --git a/ansible_collections/ngine_io/exoscale/.github/workflows/sanity.yml b/ansible_collections/ngine_io/exoscale/.github/workflows/sanity.yml
index 7e0fab5b9..b646882e0 100644
--- a/ansible_collections/ngine_io/exoscale/.github/workflows/sanity.yml
+++ b/ansible_collections/ngine_io/exoscale/.github/workflows/sanity.yml
@@ -1,31 +1,42 @@
name: Sanity
on:
-- pull_request
+ push:
+ branches:
+ - master
+ schedule:
+ - cron: "5 12 * * *"
+ pull_request:
+ workflow_call:
+ workflow_dispatch:
jobs:
sanity:
name: Sanity (${{ matrix.ansible }})
+ runs-on: ubuntu-20.04
+ defaults:
+ run:
+ working-directory: ansible_collections/ngine_io/exoscale
strategy:
matrix:
ansible:
- - stable-2.10
- - stable-2.9
- - devel
- runs-on: ubuntu-latest
+ - stable-2.14
+ - devel
steps:
+ - name: Check out code
+ uses: actions/checkout@v3
+ with:
+ path: ansible_collections/ngine_io/exoscale
- - name: Check out code
- uses: actions/checkout@v1
- with:
- path: ansible_collections/ngine_io/exoscale
+ - name: Set up Python 3
+ uses: actions/setup-python@v4
+ with:
+ python-version: "3.10"
- - name: Set up Python 3.6
- uses: actions/setup-python@v1
- with:
- python-version: 3.6
+ - name: Install ansible-base (${{ matrix.ansible }})
+ run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
- - name: Install ansible-base (${{ matrix.ansible }})
- run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
+ - name: Install dependencies
+ run: ansible-galaxy collection install -p ../../ ngine_io.cloudstack
- - name: Run sanity tests
- run: ansible-test sanity --docker -v --color --python 3.6
+ - name: Run sanity tests
+ run: ansible-test sanity --docker -v --color
diff --git a/ansible_collections/ngine_io/exoscale/CHANGELOG.rst b/ansible_collections/ngine_io/exoscale/CHANGELOG.rst
index 54909f89b..c2292e89e 100644
--- a/ansible_collections/ngine_io/exoscale/CHANGELOG.rst
+++ b/ansible_collections/ngine_io/exoscale/CHANGELOG.rst
@@ -5,5 +5,13 @@ Exoscale Ansible Collection Release Notes
.. contents:: Topics
+v1.1.0
+======
+
+New Modules
+-----------
+
+- ngine_io.exoscale.instance_rdns_record - Manages reverse DNS records for Exoscale compute instances.
+
v1.0.0
======
diff --git a/ansible_collections/ngine_io/exoscale/FILES.json b/ansible_collections/ngine_io/exoscale/FILES.json
index f725ab2d6..5c567253c 100644
--- a/ansible_collections/ngine_io/exoscale/FILES.json
+++ b/ansible_collections/ngine_io/exoscale/FILES.json
@@ -8,6 +8,13 @@
"format": 1
},
{
+ "name": "CHANGELOG.rst",
+ "ftype": "file",
+ "chksum_type": "sha256",
+ "chksum_sha256": "8933e18b420ebf5ac2f08614062358f129ac675b653e6123994a89475199d2b3",
+ "format": 1
+ },
+ {
"name": "tests",
"ftype": "dir",
"chksum_type": null,
@@ -22,6 +29,13 @@
"format": 1
},
{
+ "name": "tests/legacy/exoscale.yml",
+ "ftype": "file",
+ "chksum_type": "sha256",
+ "chksum_sha256": "38d542d66924d6e8fd7991ffc2e73544cfd7f88cdd4734ba47734b8ec86ea3fb",
+ "format": 1
+ },
+ {
"name": "tests/legacy/roles",
"ftype": "dir",
"chksum_type": null,
@@ -64,45 +78,45 @@
"format": 1
},
{
- "name": "tests/legacy/exoscale.yml",
+ "name": "changelogs",
+ "ftype": "dir",
+ "chksum_type": null,
+ "chksum_sha256": null,
+ "format": 1
+ },
+ {
+ "name": "changelogs/changelog.yaml",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "38d542d66924d6e8fd7991ffc2e73544cfd7f88cdd4734ba47734b8ec86ea3fb",
+ "chksum_sha256": "3e8edd11d87e03989560cbe31d55b406ecc5f3253afa4382cc20f79aa6ea4f25",
"format": 1
},
{
- "name": "CHANGELOG.rst",
+ "name": "changelogs/config.yaml",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "f3a697694dc57ace9e8600b5b2afbff42deeb76739d55cf66d844aec1ebb5dbf",
+ "chksum_sha256": "6077ffbd67c5ad687d45cb43010521973fe662e82c2f167c5121016803861cea",
"format": 1
},
{
- "name": "CONTRIBUTING.md",
+ "name": "changelogs/.gitignore",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "d61725d614410e2ee0a900fb0f6b6d742ad8fb689ae27c4d6a3a7f89e82fc791",
+ "chksum_sha256": "919ef00776e7d2ff349950ac4b806132aa9faf006e214d5285de54533e443b33",
"format": 1
},
{
- "name": "meta",
+ "name": "changelogs/fragments",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
- "name": "meta/runtime.yml",
- "ftype": "file",
- "chksum_type": "sha256",
- "chksum_sha256": "65ddf4c03edf730c4bf7da2184d83dfd28e790cb816ef1f9d82904273cb0c854",
- "format": 1
- },
- {
- "name": "README.md",
+ "name": "changelogs/fragments/.keep",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "476a74dcdd9be0337c38135c7ab2f0f65de2ab4fdff679ceaa66b04f3e844811",
+ "chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"format": 1
},
{
@@ -130,7 +144,7 @@
"name": "plugins/doc_fragments/exoscale.py",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "c484b770aa74ea4fbd70bf2f673af2e7f469ad732e818223152a356a5b9fd861",
+ "chksum_sha256": "d86f0fc819f87865a54d53e557c43c06ebe2307fe6d6bed3398a3620e6694016",
"format": 1
},
{
@@ -144,7 +158,7 @@
"name": "plugins/module_utils/exoscale.py",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "27754664282f766b3ad37dde8ac45d67495e3bc599e4bfa4a089a11819038311",
+ "chksum_sha256": "1eb5c5bb5f470db43015ea80b3b83a82c8f54ba0145dfd1ce2dff961455bfc54",
"format": 1
},
{
@@ -158,7 +172,7 @@
"name": "plugins/modules/exo_dns_domain.py",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "fe708671d29b57cdf89f39aee4b0f81672db58030a92b832bf6b78008e080b80",
+ "chksum_sha256": "c935301e351f7edf575a57690a18d414d533474411fbc0545a09597ef16a84f3",
"format": 1
},
{
@@ -169,52 +183,45 @@
"format": 1
},
{
- "name": "plugins/modules/exo_dns_record.py",
+ "name": "plugins/modules/instance_rdns_record.py",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "920ee4da3ced628cec9e998467ec04cd84db296b47e36225cf0693445fa483a9",
- "format": 1
- },
- {
- "name": "changelogs",
- "ftype": "dir",
- "chksum_type": null,
- "chksum_sha256": null,
+ "chksum_sha256": "23076872f3e72d7f40235a451c4a9379c2ee3a3c95a8720852d824999f6d8422",
"format": 1
},
{
- "name": "changelogs/config.yaml",
+ "name": "plugins/modules/exo_dns_record.py",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "6077ffbd67c5ad687d45cb43010521973fe662e82c2f167c5121016803861cea",
+ "chksum_sha256": "12ba02ca52c73008913c66b33550873605d0b0c224aca18781f65c8aa39581aa",
"format": 1
},
{
- "name": "changelogs/fragments",
+ "name": "meta",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
- "name": "changelogs/fragments/.keep",
+ "name": "meta/runtime.yml",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
+ "chksum_sha256": "65ddf4c03edf730c4bf7da2184d83dfd28e790cb816ef1f9d82904273cb0c854",
"format": 1
},
{
- "name": "changelogs/.gitignore",
+ "name": "README.md",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "919ef00776e7d2ff349950ac4b806132aa9faf006e214d5285de54533e443b33",
+ "chksum_sha256": "9a597bfa46bbaf1cf2af965225a512c850b7b97b6f2b8b56cf75d853da649467",
"format": 1
},
{
- "name": "changelogs/changelog.yaml",
+ "name": "CONTRIBUTING.md",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "2dbaa843cb55fda031c7fa291a37ff6a59c596763cce1eaf97fd72b3a1761d92",
+ "chksum_sha256": "d61725d614410e2ee0a900fb0f6b6d742ad8fb689ae27c4d6a3a7f89e82fc791",
"format": 1
},
{
@@ -235,14 +242,21 @@
"name": ".github/workflows/publish.yml",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "c529e2810ae1f02ea98dcae1b78241d21a5988496ed5389b2ce8c37395323756",
+ "chksum_sha256": "968d296da538330e7547e13d72957e5efd43eda675d75febb3d2e7a041ec0047",
"format": 1
},
{
"name": ".github/workflows/sanity.yml",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "33964a78f085244db7db9904c39776a726cd4cfef48c3b1dcb5e1cf57714d223",
+ "chksum_sha256": "45a61141d4e4e0f72d0ba02045b0d6b0f0662fa7565e05c5bff5c8d53ca5d858",
+ "format": 1
+ },
+ {
+ "name": ".github/dependabot.yml",
+ "ftype": "file",
+ "chksum_type": "sha256",
+ "chksum_sha256": "d207e80d10726360f2046d4b2473a3cfd9f9eca99590281fa39d88f78e745145",
"format": 1
}
],
diff --git a/ansible_collections/ngine_io/exoscale/MANIFEST.json b/ansible_collections/ngine_io/exoscale/MANIFEST.json
index acebe1576..f707a1aaf 100644
--- a/ansible_collections/ngine_io/exoscale/MANIFEST.json
+++ b/ansible_collections/ngine_io/exoscale/MANIFEST.json
@@ -2,7 +2,7 @@
"collection_info": {
"namespace": "ngine_io",
"name": "exoscale",
- "version": "1.0.0",
+ "version": "1.1.0",
"authors": [
"Ren\u00e9 Moser <mail@renemoser.net>"
],
@@ -18,7 +18,9 @@
"GPL-3.0-or-later"
],
"license_file": null,
- "dependencies": {},
+ "dependencies": {
+ "ngine_io.cloudstack": ">=1.0.0"
+ },
"repository": "https://github.com/ngine-io/ansible-collection-exoscale",
"documentation": "",
"homepage": "https://github.com/ngine-io/ansible-collection-exoscale",
@@ -28,7 +30,7 @@
"name": "FILES.json",
"ftype": "file",
"chksum_type": "sha256",
- "chksum_sha256": "dbbe7cf8b0656632d858a3bcec7ed6049ee30663c1ed9488392b80c53311d4a4",
+ "chksum_sha256": "45043adcb9cba1598dc0e4fd8b7d896a1cf1e547c07168d6e60e7d383031d2c4",
"format": 1
},
"format": 1
diff --git a/ansible_collections/ngine_io/exoscale/README.md b/ansible_collections/ngine_io/exoscale/README.md
index 824f6b779..efae55085 100644
--- a/ansible_collections/ngine_io/exoscale/README.md
+++ b/ansible_collections/ngine_io/exoscale/README.md
@@ -1,5 +1,4 @@
-![Collection integration](https://github.com/ngine-io/ansible-collection-exoscale/workflows/Collection%20integration/badge.svg)
- [![Codecov](https://img.shields.io/codecov/c/github/ngine-io/ansible-collection-exoscale)](https://codecov.io/gh/ngine-io/ansible-collection-exoscale)
+![Collection integration](https://github.com/ngine-io/ansible-collection-exoscale/workflows/Sanity/badge.svg)
[![License](https://img.shields.io/badge/license-GPL%20v3.0-brightgreen.svg)](LICENSE)
# Ansible Collection for exoscale Cloud
diff --git a/ansible_collections/ngine_io/exoscale/changelogs/changelog.yaml b/ansible_collections/ngine_io/exoscale/changelogs/changelog.yaml
index 4eef701ce..948507e75 100644
--- a/ansible_collections/ngine_io/exoscale/changelogs/changelog.yaml
+++ b/ansible_collections/ngine_io/exoscale/changelogs/changelog.yaml
@@ -2,3 +2,9 @@ ancestor: null
releases:
1.0.0:
release_date: '2020-08-15'
+ 1.1.0:
+ modules:
+ - description: Manages reverse DNS records for Exoscale compute instances.
+ name: instance_rdns_record
+ namespace: ''
+ release_date: '2023-08-23'
diff --git a/ansible_collections/ngine_io/exoscale/plugins/doc_fragments/exoscale.py b/ansible_collections/ngine_io/exoscale/plugins/doc_fragments/exoscale.py
index 52ea2cd49..28081074f 100644
--- a/ansible_collections/ngine_io/exoscale/plugins/doc_fragments/exoscale.py
+++ b/ansible_collections/ngine_io/exoscale/plugins/doc_fragments/exoscale.py
@@ -4,6 +4,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
+
__metaclass__ = type
@@ -38,7 +39,7 @@ options:
description:
- Validate SSL certs of the Exoscale DNS API.
type: bool
- default: yes
+ default: true
requirements:
- python >= 2.6
notes:
diff --git a/ansible_collections/ngine_io/exoscale/plugins/module_utils/exoscale.py b/ansible_collections/ngine_io/exoscale/plugins/module_utils/exoscale.py
index 44933b1b0..9e1d32fc7 100644
--- a/ansible_collections/ngine_io/exoscale/plugins/module_utils/exoscale.py
+++ b/ansible_collections/ngine_io/exoscale/plugins/module_utils/exoscale.py
@@ -2,13 +2,14 @@
# Copyright (c) 2016, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
+
__metaclass__ = type
import os
-from ansible.module_utils.six.moves import configparser
-from ansible.module_utils.six import integer_types, string_types
from ansible.module_utils._text import to_native, to_text
+from ansible.module_utils.six import integer_types, string_types
+from ansible.module_utils.six.moves import configparser
from ansible.module_utils.urls import fetch_url
EXO_DNS_BASEURL = "https://api.exoscale.ch/dns/v1"
@@ -80,7 +81,7 @@ class ExoDns(object):
# Look at CLOUDSTACK_CONFIG first if present
if 'CLOUDSTACK_CONFIG' in os.environ:
paths += (os.path.expanduser(os.environ['CLOUDSTACK_CONFIG']),)
- if not any([os.path.exists(c) for c in paths]):
+ if not any([os.path.exists(c) for c in paths]): # pylint: disable=use-a-generator
self.module.fail_json(msg="Config file not found. Tried : %s" % ", ".join(paths))
conf = configparser.ConfigParser()
diff --git a/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_domain.py b/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_domain.py
index 334c5c02b..a8573b51f 100644
--- a/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_domain.py
+++ b/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_domain.py
@@ -5,6 +5,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
+
__metaclass__ = type
@@ -132,7 +133,9 @@ exo_dns_domain:
'''
from ansible.module_utils.basic import AnsibleModule
-from ..module_utils.exoscale import ExoDns, exo_dns_argument_spec, exo_dns_required_together
+
+from ..module_utils.exoscale import (ExoDns, exo_dns_argument_spec,
+ exo_dns_required_together)
class ExoDnsDomain(ExoDns):
diff --git a/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_record.py b/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_record.py
index 8da3491eb..8153ff849 100644
--- a/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_record.py
+++ b/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_record.py
@@ -5,6 +5,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
+
__metaclass__ = type
@@ -56,7 +57,7 @@ options:
- Only allowed for a few record types, e.g. C(record_type=A), C(record_type=NS) or C(record_type=MX).
- I(content) will not be updated, instead it is used as a key to find existing records.
type: bool
- default: no
+ default: false
state:
description:
- State of the record.
@@ -186,8 +187,9 @@ exo_dns_record:
'''
from ansible.module_utils.basic import AnsibleModule
-from ..module_utils.exoscale import ExoDns, exo_dns_argument_spec, exo_dns_required_together
+from ..module_utils.exoscale import (ExoDns, exo_dns_argument_spec,
+ exo_dns_required_together)
EXO_RECORD_TYPES = [
'A',
diff --git a/ansible_collections/ngine_io/exoscale/plugins/modules/instance_rdns_record.py b/ansible_collections/ngine_io/exoscale/plugins/modules/instance_rdns_record.py
new file mode 100644
index 000000000..863370d17
--- /dev/null
+++ b/ansible_collections/ngine_io/exoscale/plugins/modules/instance_rdns_record.py
@@ -0,0 +1,186 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# (c) 2019, Lorenz Schori <lo@znerol.ch>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from __future__ import absolute_import, division, print_function
+
+__metaclass__ = type
+
+
+DOCUMENTATION = '''
+---
+module: instance_rdns_record
+short_description: Manages reverse DNS records for Exoscale compute instances.
+description:
+ - Set and unset reverse DNS record on Exoscale instance.
+version_added: "1.1.0"
+author: "Lorenz Schori (@znerol)"
+options:
+ name:
+ description:
+ - Name of the compute instance
+ required: true
+ type: str
+ content:
+ aliases: [ 'value' ]
+ description:
+ - Reverse DSN name of the compute instance. Required if state=present.
+ type: str
+ state:
+ description:
+ - State of the record.
+ default: present
+ choices: [ 'present', 'absent' ]
+ type: str
+extends_documentation_fragment: ngine_io.cloudstack.cloudstack
+'''
+
+EXAMPLES = '''
+- name: Set the reverse DNS for a compute instance
+ ngine_io.exoscale.instance_rdns_record:
+ name: web-vm-1
+ content: www.example.com
+
+- name: Delete the reverse DNS for a compute instance
+ ngine_io.exoscale.instance_rdns_record:
+ name: web-vm-1
+ state: absent
+'''
+
+RETURN = '''
+---
+instance_rdns_domain:
+ description: Reverse DSN name of the compute instance
+ returned: success
+ type: str
+'''
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible_collections.ngine_io.cloudstack.plugins.module_utils.cloudstack import (
+ AnsibleCloudStack, cs_argument_spec, cs_required_together)
+
+
+class InstanceRdnsRecord(AnsibleCloudStack):
+
+ def __init__(self, module):
+ super(InstanceRdnsRecord, self).__init__(module)
+
+ self.name = self.module.params.get('name')
+ self.content = self.module.params.get('content')
+
+ self.returns = {
+ 'domain': 'domain'
+ }
+
+ self.instance = None
+
+ def get_instance(self):
+ instance = self.instance
+ if not instance:
+ args = {
+ 'fetch_list': True,
+ }
+ # Do not pass zoneid, as the instance name must be unique across
+ # zones.
+ instances = self.query_api('listVirtualMachines', **args)
+ if instances:
+ for v in instances:
+ if self.name.lower() in [v['name'].lower(), v['displayname'].lower(), v['id']]:
+ self.instance = v
+ break
+
+ return self.instance
+
+ def get_record(self, instance):
+ result = {}
+
+ res = self.query_api('queryReverseDnsForVirtualMachine',
+ id=instance['id'])
+ nics = res['virtualmachine'].get('nic', [])
+
+ defaultnics = [nic for nic in nics if nic.get('isdefault', False)]
+
+ if len(defaultnics) > 0:
+ domains = [record['domainname'] for record
+ in defaultnics[0].get('reversedns', [])
+ if 'domainname' in record]
+
+ if len(domains) > 0:
+ result = {
+ 'domainname': domains[0],
+ }
+
+ return result
+
+ def present_record(self):
+ instance = self.get_instance()
+
+ if not instance:
+ self.module.fail_json(
+ msg="No compute instance with name=%s found. " % self.name)
+
+ data = {
+ 'domainname': self.content,
+ }
+ record = self.get_record(instance)
+ if self.has_changed(data, record):
+ self.result['changed'] = True
+ self.result['diff']['before'] = record
+ self.result['diff']['after'] = data
+ if not self.module.check_mode:
+ self.query_api('updateReverseDnsForVirtualMachine',
+ id=instance['id'],
+ domainname=data['domainname'])
+
+ return data
+
+ def absent_record(self):
+ instance = self.get_instance()
+
+ if instance:
+ record = self.get_record(instance)
+ if record:
+ self.result['diff']['before'] = record
+ self.result['changed'] = True
+ if not self.module.check_mode:
+ self.query_api('deleteReverseDnsFromVirtualMachine',
+ id=instance['id'])
+
+ return record
+
+ def get_result(self, resource):
+ self.result['instance_rdns_domain'] = resource
+ return self.result
+
+
+def main():
+ argument_spec = cs_argument_spec()
+ argument_spec.update(dict(
+ name=dict(required=True),
+ content=dict(aliases=['value']),
+ state=dict(choices=['present', 'absent'], default='present'),
+ ))
+
+ module = AnsibleModule(
+ argument_spec=argument_spec,
+ required_together=cs_required_together(),
+ required_if=[
+ ('state', 'present', ['content']),
+ ],
+ supports_check_mode=True,
+ )
+
+ instance_rdns_record = InstanceRdnsRecord(module)
+ if module.params.get('state') == "present":
+ record = instance_rdns_record.present_record()
+ else:
+ record = instance_rdns_record.absent_record()
+
+ result = instance_rdns_record.get_result(record)
+ module.exit_json(**result)
+
+
+if __name__ == '__main__':
+ main()