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

cloudstack: cs_facts: add option for custom meta data host (#27290)

This commit is contained in:
René Moser 2017-07-26 11:49:15 +02:00 committed by GitHub
parent e2d874c744
commit c16b1844a9

View file

@ -35,8 +35,6 @@ options:
filter: filter:
description: description:
- Filter for a specific fact. - Filter for a specific fact.
required: false
default: null
choices: choices:
- cloudstack_service_offering - cloudstack_service_offering
- cloudstack_availability_zone - cloudstack_availability_zone
@ -46,6 +44,11 @@ options:
- cloudstack_local_ipv4 - cloudstack_local_ipv4
- cloudstack_instance_id - cloudstack_instance_id
- cloudstack_user_data - cloudstack_user_data
meta_data_host:
description:
- Host or IP of the meta data API service.
- If not set, determination by parsing the dhcp lease file.
version_added: "2.4"
requirements: [ 'yaml' ] requirements: [ 'yaml' ]
''' '''
@ -57,6 +60,12 @@ EXAMPLES = '''
# Gather specific fact on instances # Gather specific fact on instances
- name: Gather cloudstack facts - name: Gather cloudstack facts
cs_facts: filter=cloudstack_instance_id cs_facts: filter=cloudstack_instance_id
# Gather specific fact on instances with a given meta_data_host
- name: Gather cloudstack facts
cs_facts:
filter: cloudstack_instance_id
meta_data_host: 169.254.169.254
''' '''
RETURN = ''' RETURN = '''
@ -187,7 +196,9 @@ class CloudStackFacts(object):
def _get_api_ip(self): def _get_api_ip(self):
"""Return the IP of the DHCP server.""" """Return the IP of the DHCP server."""
if not self.api_ip: if module.params.get('meta_data_host'):
return module.params.get('meta_data_host')
elif not self.api_ip:
dhcp_lease_file = self._get_dhcp_lease_file() dhcp_lease_file = self._get_dhcp_lease_file()
for line in open(dhcp_lease_file): for line in open(dhcp_lease_file):
if 'dhcp-server-identifier' in line: if 'dhcp-server-identifier' in line:
@ -214,6 +225,7 @@ def main():
'cloudstack_instance_id', 'cloudstack_instance_id',
'cloudstack_user_data', 'cloudstack_user_data',
]), ]),
meta_data_host=dict(),
), ),
supports_check_mode=False supports_check_mode=False
) )