1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

cs_instance_facts: add host return (#40307)

This commit is contained in:
René Moser 2018-05-17 12:17:49 +02:00 committed by GitHub
parent 912e07a036
commit 1f0c2ca6c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 29 deletions

View file

@ -43,29 +43,33 @@ EXAMPLES = '''
cs_instance_facts:
name: web-vm-1
delegate_to: localhost
register: vm
- debug:
var: cloudstack_instance
- debug:
var: vm
'''
RETURN = '''
---
cloudstack_instance.id:
id:
description: UUID of the instance.
returned: success
type: string
sample: 04589590-ac63-4ffc-93f5-b698b8ac38b6
cloudstack_instance.name:
name:
description: Name of the instance.
returned: success
type: string
sample: web-01
cloudstack_instance.display_name:
display_name:
description: Display name of the instance.
returned: success
type: string
sample: web-01
cloudstack_instance.group:
group:
description: Group name of the instance is related.
returned: success
type: string
@ -75,97 +79,103 @@ created:
returned: success
type: string
sample: 2014-12-01T14:57:57+0100
cloudstack_instance.password_enabled:
password_enabled:
description: True if password setting is enabled.
returned: success
type: boolean
sample: true
cloudstack_instance.password:
password:
description: The password of the instance if exists.
returned: success
type: string
sample: Ge2oe7Do
cloudstack_instance.ssh_key:
ssh_key:
description: Name of SSH key deployed to instance.
returned: success
type: string
sample: key@work
cloudstack_instance.domain:
domain:
description: Domain the instance is related to.
returned: success
type: string
sample: example domain
cloudstack_instance.account:
account:
description: Account the instance is related to.
returned: success
type: string
sample: example account
cloudstack_instance.project:
project:
description: Name of project the instance is related to.
returned: success
type: string
sample: Production
cloudstack_instance.default_ip:
default_ip:
description: Default IP address of the instance.
returned: success
type: string
sample: 10.23.37.42
cloudstack_instance.public_ip:
public_ip:
description: Public IP address with instance via static NAT rule.
returned: success
type: string
sample: 1.2.3.4
cloudstack_instance.iso:
iso:
description: Name of ISO the instance was deployed with.
returned: success
type: string
sample: Debian-8-64bit
cloudstack_instance.template:
template:
description: Name of template the instance was deployed with.
returned: success
type: string
sample: Debian-8-64bit
cloudstack_instance.service_offering:
service_offering:
description: Name of the service offering the instance has.
returned: success
type: string
sample: 2cpu_2gb
cloudstack_instance.zone:
zone:
description: Name of zone the instance is in.
returned: success
type: string
sample: ch-gva-2
cloudstack_instance.state:
state:
description: State of the instance.
returned: success
type: string
sample: Running
cloudstack_instance.security_groups:
security_groups:
description: Security groups the instance is in.
returned: success
type: list
sample: '[ "default" ]'
cloudstack_instance.affinity_groups:
affinity_groups:
description: Affinity groups the instance is in.
returned: success
type: list
sample: '[ "webservers" ]'
cloudstack_instance.tags:
tags:
description: List of resource tags associated with the instance.
returned: success
type: dict
sample: '[ { "key": "foo", "value": "bar" } ]'
cloudstack_instance.hypervisor:
hypervisor:
description: Hypervisor related to this instance.
returned: success
type: string
sample: KVM
cloudstack_instance.instance_name:
host:
description: Host the instance is running on.
returned: success and instance is running
type: string
sample: host01.example.com
version_added: '2.6'
instance_name:
description: Internal name of the instance (ROOT admin only).
returned: success
type: string
sample: i-44-3992-VM
cloudstack_instance.volumes:
volumes:
description: List of dictionaries of the volumes attached to the instance.
returned: success
type: list
@ -192,6 +202,7 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack):
'isoname': 'iso',
'templatename': 'template',
'keypair': 'ssh_key',
'hostname': 'host',
}
self.facts = {
'cloudstack_instance': None,
@ -238,8 +249,7 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack):
instance = self.get_instance()
if not instance:
self.module.fail_json(msg="Instance not found: %s" % self.module.params.get('name'))
self.facts['cloudstack_instance'] = self.get_result(instance)
return self.facts
return instance
def get_result(self, instance):
super(AnsibleCloudStackInstanceFacts, self).get_result(instance)
@ -277,10 +287,12 @@ def main():
argument_spec=argument_spec,
supports_check_mode=True,
)
cs_instance_facts = AnsibleCloudStackInstanceFacts(module=module).run()
cs_facts_result = dict(changed=False, ansible_facts=cs_instance_facts)
module.exit_json(**cs_facts_result)
acs_instance_facts = AnsibleCloudStackInstanceFacts(module=module)
cs_instance_facts = acs_instance_facts.get_result_and_facts(
facts_name='cloudstack_instance',
resource=acs_instance_facts.run()
)
module.exit_json(**cs_instance_facts)
if __name__ == '__main__':

View file

@ -48,6 +48,13 @@
that:
- instance_facts is successful
- instance_facts is not changed
- instance_facts.id == instance.id
- instance_facts.domain == instance.domain
- instance_facts.account == instance.account
- instance_facts.zone == instance.zone
- instance_facts.name == instance.name
- instance_facts.service_offering == instance.service_offering
- instance_facts.host != ""
- cloudstack_instance.id == instance.id
- cloudstack_instance.domain == instance.domain
- cloudstack_instance.account == instance.account
@ -64,6 +71,13 @@
that:
- instance_facts is successful
- instance_facts is not changed
- instance_facts.id == instance.id
- instance_facts.domain == instance.domain
- instance_facts.account == instance.account
- instance_facts.zone == instance.zone
- instance_facts.name == instance.name
- instance_facts.service_offering == instance.service_offering
- instance_facts.host != ""
- cloudstack_instance.id == instance.id
- cloudstack_instance.domain == instance.domain
- cloudstack_instance.account == instance.account