One-deploy-validation fails with 1 Host

I’m playing with the one-deploy-validation repo.

It fails when there is only 1 host in the infrastructure.

It fails in the one-deploy-validation/playbooks/validation.yml playbook with this error:

[ERROR]: Task failed: Finalization of task args for 'ansible.builtin.set_fact' failed: Error while resolving value for 'host_name_to_hostname_cmd': object of type 'str' has no attribute 'NAME'

Task failed.
Origin: one-deploy-validation/playbooks/validation.yml:43:11

41           no_log: true
42
43         - name: Set fact with host to "hostname_cmd" mapping
             ^ column 11

It fails because it expects a list of dict in the onehost list -j | jq . command, something like this:

{
  "HOST_POOL": {
    "HOST": [
      {
        "ID": "1",
        "NAME": "1.1.1.1",
         ......

But for 1 host, that command returns just a dict with the host info:

{
  "HOST_POOL": {
    "HOST": {
      "ID": "0",
      "NAME": "1.1.1.1",

The code that fails is:

        - name: Set fact with host to "hostname_cmd" mapping
          set_fact:
            host_name_to_hostname_cmd: >-
                {{
                  dict(
                    (host_list_json.stdout | from_json).HOST_POOL.HOST
                    | map(attribute='NAME')
                    | zip(
                        (host_list_json.stdout | from_json).HOST_POOL.HOST
                        | map(attribute='TEMPLATE')
                        | map(attribute='HOSTNAME')
                      )
                  )
                }}

And the following code seems to fix it:

        - name: Set fact with host to "hostname_cmd" mapping
          set_fact:
            host_name_to_hostname_cmd: >-
              {{
                dict(
                  (
                    (
                      [ (host_list_json.stdout | from_json).HOST_POOL.HOST ]
                      if ((host_list_json.stdout | from_json).HOST_POOL.HOST is mapping)
                      else (host_list_json.stdout | from_json).HOST_POOL.HOST
                    )
                    | map(attribute='NAME')
                    | zip(
                        (
                          [ (host_list_json.stdout | from_json).HOST_POOL.HOST ]
                          if ((host_list_json.stdout | from_json).HOST_POOL.HOST is mapping)
                          else (host_list_json.stdout | from_json).HOST_POOL.HOST
                        )
                        | map(attribute='TEMPLATE')
                        | map(attribute='HOSTNAME')
                      )
                  )
                )
              }}
1 Like

Hello.

It looks exactly like my problem with fireedge API.

Hi,

Thanks a lot for reporting the issue and proposing a fix.

We will create a fix shortly, as recommended by @mopala the simplest is to use “flatten” filter, we will verify it for this case.
I opened this issue to track it: Validation playbook fails with 1 host · Issue #24 · OpenNebula/one-deploy-validation · GitHub

@DaD The relationship is just how the JSON outputs handle when there is a single element vs when there are multiple. But it is not related to this issue in one-deploy-validation repo in any other way.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.