ansible_modules icon indicating copy to clipboard operation
ansible_modules copied to clipboard

[Docs]: Provided examples for export_templates are for custom_link

Open felbinger opened this issue 1 year ago • 0 comments

Change Type

Correction

Area

Other

Proposed Changes

The provided examples for the export_templates do not work. It looks like they have just been cloned from custom_link and adjusted in some way, but not fully. See github.com/netbox-community/ansible_modules/blob/devel/plugins/modules/netbox_export_template.py#L77-L102.

I would suggest something like this, it also shows a bit of the usage of the templating system.

- name: "Test NetBox export_templates module"
  connection: local
  hosts: localhost  
  tasks:
    - name: "Ensure export template for /etc/hosts entries exists"
      netbox.netbox.netbox_export_template:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          content_types: ["dcim.device", "virtualization.virtualmachine"]
          name: /etc/hosts
          description: "Generate entries for /etc/hosts"
          as_attachment: true
          template_code: !unsafe |
            {% for vm in queryset -%}
            {%- if vm.primary_ip4 and vm.primary_ip6 %}
            {{ vm.primary_ip4.address.ip }} {{ vm.primary_ip6.address.ip }} {{ vm }}
            {%- elif vm.primary_ip4 %}
            {{ vm.primary_ip4.address.ip }} {{ vm }}
            {%- elif vm.primary_ip6 %}
            {{ vm.primary_ip6.address.ip }} {{ vm }}
            {%- endif -%}
            {%- endfor %}

    - name: Delete the export template
      netbox.netbox.netbox_export_template:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          content_type: "dcim.device"
          name: /etc/hosts
        state: absent

The part right below (see github.com/netbox-community/ansible_modules/blob/devel/plugins/modules/netbox_export_template.py#L105-L108) also doesn't look right, but I don't know how to adjust it.

felbinger avatar Apr 17 '24 11:04 felbinger