diff --git a/changelogs/fragments/60915-smartos_image_facts-info-rename.yml b/changelogs/fragments/60915-smartos_image_facts-info-rename.yml new file mode 100644 index 00000000000..f59751d71c6 --- /dev/null +++ b/changelogs/fragments/60915-smartos_image_facts-info-rename.yml @@ -0,0 +1,3 @@ +minor_changes: +- The ``smartos_image_facts`` module has been renamed to ``smartos_image_info``. + When called with the new name, the module no longer returns ``ansible_facts``. diff --git a/docs/docsite/rst/porting_guides/porting_guide_2.9.rst b/docs/docsite/rst/porting_guides/porting_guide_2.9.rst index ed298d38609..71aa8202537 100644 --- a/docs/docsite/rst/porting_guides/porting_guide_2.9.rst +++ b/docs/docsite/rst/porting_guides/porting_guide_2.9.rst @@ -453,6 +453,9 @@ be removed in Ansible 2.13. Please update update your playbooks accordingly. To access return values, :ref:`register a variable `. * The ``redshift_facts`` module was renamed to :ref:`redshift_info `. * The ``route53_facts`` module was renamed to :ref:`route53_info `. +* The ``smartos_image_facts`` module was renamed to :ref:`smartos_image_info `. + When called with the new name, the module no longer returns ``ansible_facts``. + To access return values, :ref:`register a variable `. * The ``vertica_facts`` module was renamed to :ref:`vertica_info `. When called with the new name, the module no longer returns ``ansible_facts``. To access return values, :ref:`register a variable `. diff --git a/lib/ansible/modules/cloud/smartos/_smartos_image_facts.py b/lib/ansible/modules/cloud/smartos/_smartos_image_facts.py new file mode 120000 index 00000000000..d7206ed938a --- /dev/null +++ b/lib/ansible/modules/cloud/smartos/_smartos_image_facts.py @@ -0,0 +1 @@ +smartos_image_info.py \ No newline at end of file diff --git a/lib/ansible/modules/cloud/smartos/smartos_image_facts.py b/lib/ansible/modules/cloud/smartos/smartos_image_info.py similarity index 61% rename from lib/ansible/modules/cloud/smartos/smartos_image_facts.py rename to lib/ansible/modules/cloud/smartos/smartos_image_info.py index 589f640400e..2772b703ebc 100644 --- a/lib/ansible/modules/cloud/smartos/smartos_image_facts.py +++ b/lib/ansible/modules/cloud/smartos/smartos_image_info.py @@ -15,11 +15,12 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', DOCUMENTATION = ''' --- -module: smartos_image_facts +module: smartos_image_info short_description: Get SmartOS image details. description: - - Retrieve facts about all installed images on SmartOS. Facts will be - inserted to the ansible_facts key. + - Retrieve information about all installed images on SmartOS. + - This module was called C(smartos_image_facts) before Ansible 2.9, returning C(ansible_facts). + Note that the M(smartos_image_info) module no longer returns C(ansible_facts)! version_added: "2.2" author: Adam Števko (@xen0l) options: @@ -32,22 +33,31 @@ options: ''' EXAMPLES = ''' -# Return facts about all installed images. -- smartos_image_facts: +# Return information about all installed images. +- smartos_image_info: + register: result # Return all private active Linux images. -- smartos_image_facts: filters="os=linux state=active public=false" +- smartos_image_info: filters="os=linux state=active public=false" + register: result # Show, how many clones does every image have. -- smartos_image_facts: +- smartos_image_info: + register: result -- debug: msg="{{ smartos_images[item]['name'] }}-{{smartos_images[item]['version'] }} +- debug: msg="{{ result.smartos_images[item]['name'] }}-{{ result.smartos_images[item]['version'] }} + has {{ result.smartos_images[item]['clones'] }} VM(s)" + with_items: "{{ result.smartos_images.keys() | list }}" + +# When the module is called as smartos_image_facts, return values are published +# in ansible_facts['smartos_images'] and can be used as follows. +# Note that this is deprecated and will stop working in Ansible 2.13. +- debug: msg="{{ smartos_images[item]['name'] }}-{{ smartos_images[item]['version'] }} has {{ smartos_images[item]['clones'] }} VM(s)" - with_items: "{{ smartos_images.keys() }}" + with_items: "{{ smartos_images.keys() | list }}" ''' RETURN = ''' -# this module returns ansible_facts ''' import json @@ -95,12 +105,19 @@ def main(): ), supports_check_mode=False, ) + is_old_facts = module._name == 'smartos_image_facts' + if is_old_facts: + module.deprecate("The 'smartos_image_facts' module has been renamed to 'smartos_image_info', " + "and the renamed one no longer returns ansible_facts", version='2.13') image_facts = ImageFacts(module) data = dict(smartos_images=image_facts.return_all_installed_images()) - module.exit_json(ansible_facts=data) + if is_old_facts: + module.exit_json(ansible_facts=data) + else: + module.exit_json(**data) if __name__ == '__main__': diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index a7e2718ca61..a358a7d9e68 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -2045,7 +2045,7 @@ lib/ansible/modules/cloud/scaleway/_scaleway_volume_facts.py validate-modules:E3 lib/ansible/modules/cloud/scaleway/scaleway_volume_info.py validate-modules:E338 lib/ansible/modules/cloud/smartos/imgadm.py validate-modules:E317 lib/ansible/modules/cloud/smartos/imgadm.py validate-modules:E338 -lib/ansible/modules/cloud/smartos/smartos_image_facts.py validate-modules:E338 +lib/ansible/modules/cloud/smartos/smartos_image_info.py validate-modules:E338 lib/ansible/modules/cloud/smartos/vmadm.py validate-modules:E322 lib/ansible/modules/cloud/smartos/vmadm.py validate-modules:E324 lib/ansible/modules/cloud/smartos/vmadm.py validate-modules:E326