diff --git a/build/ansible b/build/ansible index 7d0eb7b7bc06..07425f6e7456 160000 --- a/build/ansible +++ b/build/ansible @@ -1 +1 @@ -Subproject commit 7d0eb7b7bc061437ca15518904be62b889744f63 +Subproject commit 07425f6e745673d4d0df9c2654b458bb7e5179f3 diff --git a/provider/ansible.rb b/provider/ansible.rb index 2591b782c902..8407f1f43352 100644 --- a/provider/ansible.rb +++ b/provider/ansible.rb @@ -58,7 +58,7 @@ def python_type(prop) if prop.is_a? Api::Type::ResourceRef return 'str' if prop.resource_ref.readonly - return 'dict' + return nil end PYTHON_TYPE_FROM_MM_TYPE.fetch(prop.class.to_s, 'str') end diff --git a/provider/ansible/documentation.rb b/provider/ansible/documentation.rb index 6db0f614f7d2..501ba92b2e9e 100644 --- a/provider/ansible/documentation.rb +++ b/provider/ansible/documentation.rb @@ -68,7 +68,7 @@ def documentation_for_property(prop) # Builds out the RETURNS for a property. # This will eventually be converted to YAML def returns_for_property(prop) - type = python_type(prop) + type = python_type(prop) || 'str' # Type is a valid AnsibleModule type, but not a valid return type type = 'str' if type == 'path' # Complex types only mentioned in reference to RETURNS YAML block @@ -102,11 +102,10 @@ def resourceref_description(prop) [ "This field represents a link to a #{prop.resource_ref.name} resource in GCP.", 'It can be specified in two ways.', - "You can add `register: name-of-resource` to a #{module_name(prop.resource_ref)} task", - "and then set this #{prop.name.underscore} field to \"{{ name-of-resource }}\"", - "Alternatively, you can set this #{prop.name.underscore} to a dictionary", - "with the #{prop.imports} key", - "where the value is the #{prop.imports} of your #{prop.resource_ref.name}" + "First, you can place in the #{prop.imports} of the resource here as a string", + 'Alternatively, you can add `register: name-of-resource` to a', + "#{module_name(prop.resource_ref)} task", + "and then set this #{prop.name.underscore} field to \"{{ name-of-resource }}\"" ].join(' ') end diff --git a/provider/ansible/gcp_utils.py b/provider/ansible/gcp_utils.py index 7baeb2a71aef..8f6d47c3a9d2 100644 --- a/provider/ansible/gcp_utils.py +++ b/provider/ansible/gcp_utils.py @@ -19,6 +19,7 @@ from ansible.module_utils.basic import AnsibleModule, env_fallback from ansible.module_utils.six import string_types from ansible.module_utils._text import to_text +import ast import os @@ -60,8 +61,15 @@ def replace_resource_dict(item, value): else: if not item: return item - return item.get(value) + if isinstance(item, dict): + return item.get(value) + # Item could be a string or a string representing a dictionary. + try: + new_item = ast.literal_eval(item) + return replace_resource_dict(new_item, value) + except ValueError: + return new_item # Handles all authentation and HTTP sessions for GCP API calls. class GcpSession(object): diff --git a/provider/ansible/module.rb b/provider/ansible/module.rb index 90f8678f570d..85aaf3e1c011 100644 --- a/provider/ansible/module.rb +++ b/provider/ansible/module.rb @@ -55,10 +55,10 @@ def prop_options(prop, _object, spaces) ('required=True' if prop.required && !prop.default_value), ("default=#{python_literal(prop.default_value)}" \ if prop.default_value), - "type=#{quote_string(python_type(prop))}", + ("type=#{quote_string(python_type(prop))}" if python_type(prop)), (choices_enum(prop, spaces) if prop.is_a? Api::Type::Enum), ("elements=#{quote_string(python_type(prop.item_type))}" \ - if prop.is_a? Api::Type::Array), + if prop.is_a?(Api::Type::Array) && python_type(prop.item_type)), ("aliases=[#{prop.aliases.map { |x| quote_string(x) }.join(', ')}]" \ if prop.aliases) ].compact