Skip to content

Conversation

@sajagana
Copy link
Collaborator

@sajagana sajagana commented Sep 9, 2025

No description provided.

@sajagana sajagana linked an issue Sep 9, 2025 that may be closed by this pull request
@github-actions github-actions bot changed the title [bugfix] Added fix to support ansible-core 2.19 to the aci_rest module [bugfix] Added fix to support ansible-core 2.19 to the aci_rest module (DCNE-504) Sep 9, 2025
return {k: convert_payload_values_to_str(v) for k, v in data.items()}
elif isinstance(data, list):
return [convert_payload_values_to_str(item) for item in data]
elif isinstance(data, int) or isinstance(data, bool) or isinstance(data, float):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this handle JSON Null types? Looks like it does as null in JSON won't be converted to a string.
Would it be possible to add a test when a JSON value is explicitly set to null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@sajagana sajagana requested a review from samiib September 10, 2025 06:06
convert_values_to_str:
description:
- When O(convert_values_to_str=true), this attribute converts input object values to strings.
- This ensures compatibility with Jinja2 version 3.1.6 and above.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps mention the ansible version here also which introduced the change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

description:
- The page number to return.
type: int
convert_values_to_str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use full name, and do aliases for abbreviated versions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still use str and int, should we use full naming? Also as mentioned in you function naming I think we should align the two.



def convert_payload_values_to_str(data):
if data in [None, ""]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a None value is provided should this be set to an empty string? In our collection for None we typically ignore the value being added to the payload, why diverge form this behaviour here?

This could unintentionally lead to values being overwritten on an existing MO to an empty string, which should be ignored. Like a description attribute for example.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I do not understand why look for empty string, this is just a valid value that requires no translation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I don't think we should be translating JSON Null to an empty string. Instead I think null values should be ignored in the request body. Although I am unsure if ACI actually accepts null json as a valid option anywhere.

description:
- The page number to return.
type: int
convert_values_to_str:
Copy link
Collaborator

@akinross akinross Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this option, when apic typically only allows string values? there is one exception in aci rest test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter is required to control the convertion, so I keep it for now.

return {k: convert_payload_values_to_str(v) for k, v in data.items()}
elif isinstance(data, list):
return [convert_payload_values_to_str(item) for item in data]
elif isinstance(data, int) or isinstance(data, bool) or isinstance(data, float):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are boolean values handled in 2.18 vs 2.19? Is this required to convert to string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I changed the logic.



def convert_payload_values_to_str(data):
if data in [None, ""]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I don't think we should be translating JSON Null to an empty string. Instead I think null values should be ignored in the request body. Although I am unsure if ACI actually accepts null json as a valid option anywhere.

@sajagana
Copy link
Collaborator Author

sajagana commented Sep 11, 2025

Hi Team,

FYI, there is a difference between Ansible Core 2.18 and 2.19 when using a list of YAML/JSON values to populate task values in an Ansible playbook.

Sample task:

- name: Task to test value conversion
  cisco.aci.aci_rest:
    output_level: debug
    content:
      lacpIfPol:
        attributes:
          emptyString: "{{ item.emptyString }}"
          "null": "{{ item.null }}"
          bool: "{{ item.bool }}"
          int: "{{ item.int }}"
          float: "{{ item.float }}"
          string: "{{ item.string }}"
          unspecified: "{{ item.unspecified }}"
  loop: "{{ input_values | list }}"
  vars:
    input_values:
      - emptyString: ""
        "null": null
        bool: true
        int: 101
        float: 1.44
        string: Ansible
        unspecified:
Type Ansible Core 2.18 Ansible Core 2.19
Bool True True
Empty String "" ""
Float "1.44" 1.44
Int "101" 101
String "Ansible" "Ansible"
Null "" null
Unspecified Attribute Value "" null

But, no differences are observed when the values are used directly within the task.

- name: Task to test value conversion
  cisco.aci.aci_rest:
    output_level: debug
    content:
      lacpIfPol:
        attributes:
          emptyString: ""
          "null": null
          bool: false
          int: 101
          float: 1.44
          string: Ansible
          unspecified:
Key Value
emptyString ''
bool False
int 101
float 1.44
string Ansible
null None
unspecified None

return {k: convert_payload_values_to_str(v) for k, v in data.items()}
elif isinstance(data, list):
return [convert_payload_values_to_str(item) for item in data]
elif (isinstance(data, int) and not isinstance(data, bool)) or isinstance(data, float):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean only int and float types are converted to strings?
I am curious how the not bool condition is used here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python, the bool type is a subclass of the int type. Therefore, to prevent a Boolean from being converted to its string representation ("True" or "False"), we should explicitly check its type using not isinstance(data, bool).

@sajagana sajagana requested review from akinross and samiib September 17, 2025 04:20
samiib
samiib previously approved these changes Sep 18, 2025
Copy link
Collaborator

@samiib samiib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. However, looks like there are other outstanding comments.

convert_values_to_str:
description:
- When O(convert_values_to_str=true), this attribute converts input object values to strings.
- This ensures compatibility with Jinja2 version 3.1.6 and above.
Copy link
Collaborator

@gmicol gmicol Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Akini commented, we should mention the Ansible version here as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

validate_certs: '{{ aci_validate_certs | default(false) }}'
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
host: "{{ aci_hostname }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are changing this, why not set it as fact 1 time, and use those with <<?

alternatively we can also set/leverage defaults when used on every task

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@sajagana sajagana requested a review from akinross September 23, 2025 14:05
@shrsr shrsr self-requested a review September 23, 2025 17:47
shrsr
shrsr previously approved these changes Sep 23, 2025
Copy link
Collaborator

@shrsr shrsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sajagana sajagana requested review from akinross and samiib October 1, 2025 11:31
shrsr
shrsr previously approved these changes Oct 1, 2025
Copy link
Collaborator

@shrsr shrsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

gmicol
gmicol previously approved these changes Oct 1, 2025
Copy link
Collaborator

@gmicol gmicol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

anvitha-jain
anvitha-jain previously approved these changes Oct 1, 2025
Copy link
Collaborator

@anvitha-jain anvitha-jain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

akinross
akinross previously approved these changes Oct 2, 2025
Copy link
Collaborator

@akinross akinross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lhercot
Copy link
Member

lhercot commented Oct 3, 2025

Please resolve conflict

Copy link
Collaborator

@shrsr shrsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@akinross akinross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@samiib samiib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@anvitha-jain anvitha-jain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@gmicol gmicol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@lhercot lhercot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lhercot lhercot merged commit 9365b5c into CiscoDevNet:master Oct 9, 2025
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cisco.aci.aci_rest fails in ansible-core 2.19.0 (DCNE-504)

7 participants