Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-145219

[ERROR]: Task failed: object of type 'dict' has no attribute '1.1.1.1'

Linking RHIVOS CVEs to...Migration: Automation ...Sync from "Extern...XMLWordPrintable

    • rhel-system-roles-1.120.1-0.1.el10
    • None
    • Low
    • rhel-system-roles
    • 0
    • Dev ack
    • False
    • False
    • Hide

      None

      Show
      None
    • Yes
    • Red Hat Enterprise Linux
    • None
    • Enhancement
    • Hide
      Feature, enhancement:
      Reason:
      Result:
      Show
      Feature, enhancement: Reason: Result:
    • Proposed
    • Unspecified
    • Unspecified
    • Unspecified
    • None

      Hi,

      When im trying to use role in "Managed-host-to-unmanaged-host (e.g. remote is appliance)" mode Ansible throws error:

      >
      > [ERROR]: Task failed: object of type 'dict' has no attribute '1.1.1.1'
      >
      > Task failed.
      > Origin: /Users/raf/.ansible/roles/linux-system-roles.vpn/tasks/main.yml:131:7
      >
      > 129 flatten | reject('match', '^' ~ inventory_hostname ~ '$') | unique | list }}"
      > 130 block:
      > 131 - name: Create ipsec.conf files
      > ^ column 7
      >
      > <<< caused by >>>
      >
      > object of type 'dict' has no attribute '1.1.1.1'
      > Origin: /Users/raf/.ansible/roles/linux-system-roles.vpn/templates/libreswan-host-to-host.conf.j2
      >
      > failed: [vrinfrchnexus01] (item=krk) =>

      {"ansible_loop_var": "item", "changed": false, "item": "krk", "msg": "Task failed: object of type 'dict' has no attribute '1.1.1.1'"}

      >

      Host vrinfrchnexus01 is included in inventory and krk is not and variables are set as follow:
      ```
      vpn_connections:

      • auth_method: psk
        auto: ignore
        shared_key_content: nnuxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        type: tunnel
        hosts:
        vrinfrchnexus01:
        hostname: 1.1.1.1
        leftid: leftidhost
        krk:
        hostname: 2.2.2.2
        rightid: rightidhost
        subnets:
      • 10.10.0.0/16
        ```
        I asked AI to analyse main.yml and template and proposed solution worked rendering proper ipsec.conf

      ```
      +#
      +# Ansible managed
      +#
      +# system_role:vpn
      +
      +conn 1.1.1.1-to-2.2.2.2
      + left=1.1.1.1
      + leftid=leftidhost
      + right=2.2.2.2
      + rightid=rightidhost
      + rightsubnets=

      {10.10.0.0/16}

      + ikev2=insist
      + auto=ignore
      + type=tunnel
      + authby=secret
      ```

      Fixed template code:
      ```
      conn {{ tunnel.name ~ '' if 'name' in tunnel and tunnel.name else '' }}{{ host }}-to{{ otherhost }}
      left={{ host }}
      leftid={{ host | vpn_ipaddr | ternary('','@') }}{{ leftid }}

      {# --- FIX BELOW (use thishost instead host) --- #} {% if tunnel.hosts[thishost] is mapping and 'subnets' in tunnel.hosts[thishost] %}

      leftsubnets=

      { {%- for subnet in tunnel.hosts[thishost].subnets -%}

      {{ subnet }}

      {%- if not loop.last -%}

      ,

      {%- endif -%} {%- endfor -%}

      }

      {% endif %} {# --- FIX END--- #} {% endif %} {% endfor %}

      ```
      Could you verify fix and apply to main?

      Regards
      RafaƂ

              rmeggins@redhat.com Richard Megginson
              rmeggins@redhat.com Richard Megginson
              Richard Megginson Richard Megginson
              David Jez David Jez
              Zuzana Fantini Zoubkova Zuzana Fantini Zoubkova
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Created:
                Updated: