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

View file

@ -48,6 +48,13 @@
that: that:
- instance_facts is successful - instance_facts is successful
- instance_facts is not changed - 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.id == instance.id
- cloudstack_instance.domain == instance.domain - cloudstack_instance.domain == instance.domain
- cloudstack_instance.account == instance.account - cloudstack_instance.account == instance.account
@ -64,6 +71,13 @@
that: that:
- instance_facts is successful - instance_facts is successful
- instance_facts is not changed - 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.id == instance.id
- cloudstack_instance.domain == instance.domain - cloudstack_instance.domain == instance.domain
- cloudstack_instance.account == instance.account - cloudstack_instance.account == instance.account