02-23-2024 12:02 PM
Hi
any idea why I am getting API error on this?
- name: "Create SNMP Policy"
vars:
api_info: &api_info
api_private_key: "{{ api_private_key }}"
api_key_id: "{{ api_key_id }}"
api_uri: "{{ api_uri | default(omit) }}"
validate_certs: "{{ validate_certs | default(omit) }}"
state: "{{ state | default(omit) }}"
cisco.intersight.intersight_rest_api:
<<: *api_info
resource_path: /snmp/Policies
query_params:
$filter: "Name eq '{{ snmp_policy_name }}'"
api_body:
{
"Name": "{{ snmp_policy_name }}",
"Description": "{{ snmp_policy_description }}",
"Organization": {
"Moid": "{{ intersight_org.api_response.Moid }}"
},
Enabled: "true",
SnmpPort: "161",
V2Enabled: "true",
V3Enabled: "true",
SysContact: "{{ SNMP_Contact }}",
SysLocation: "{{ SNMP_Location }}"
}
register: snmp_policy
Solved! Go to Solution.
02-23-2024 02:25 PM - edited 02-23-2024 02:26 PM
What's the error you get back from Intersight? I think you might need to remove the "'s from any numeric or boolean values.
This worked for me:
- hosts: localhost
connection: local
gather_facts: false
vars:
api_info: &api_info
api_private_key: "{{ api_private_key | default(omit) }}"
api_key_id: "{{ api_key_id | default(omit) }}"
api_uri: "{{ api_uri | default(omit) }}"
org_name: default
tasks:
- name: "Get Organization {{ org_name }} Moid"
intersight_rest_api:
<<: *api_info
resource_path: /organization/Organizations
query_params:
$filter: "Name eq '{{ org_name }}'"
register: org_resp
delegate_to: localhost
tags: always
- block:
- cisco.intersight.intersight_rest_api:
<<: *api_info
resource_path: /snmp/Policies
query_params:
$filter: "Name eq 'briamorr_snmp'"
api_body: {
"Name": "briamorr_snmp",
"Description": "syslog_policy_description",
"Enabled": true,
"SnmpPort": 161,
"V2Enabled": true,
"V3Enabled": true,
SysContact: "briamorr",
SysLocation: "earth",
"Organization": {
"Moid": "{{ org_resp.api_response.Moid }}"
}
}
register: snmp_policy
02-23-2024 12:21 PM
i noticed it does not like the way these values are in the API body
02-23-2024 02:25 PM - edited 02-23-2024 02:26 PM
What's the error you get back from Intersight? I think you might need to remove the "'s from any numeric or boolean values.
This worked for me:
- hosts: localhost
connection: local
gather_facts: false
vars:
api_info: &api_info
api_private_key: "{{ api_private_key | default(omit) }}"
api_key_id: "{{ api_key_id | default(omit) }}"
api_uri: "{{ api_uri | default(omit) }}"
org_name: default
tasks:
- name: "Get Organization {{ org_name }} Moid"
intersight_rest_api:
<<: *api_info
resource_path: /organization/Organizations
query_params:
$filter: "Name eq '{{ org_name }}'"
register: org_resp
delegate_to: localhost
tags: always
- block:
- cisco.intersight.intersight_rest_api:
<<: *api_info
resource_path: /snmp/Policies
query_params:
$filter: "Name eq 'briamorr_snmp'"
api_body: {
"Name": "briamorr_snmp",
"Description": "syslog_policy_description",
"Enabled": true,
"SnmpPort": 161,
"V2Enabled": true,
"V3Enabled": true,
SysContact: "briamorr",
SysLocation: "earth",
"Organization": {
"Moid": "{{ org_resp.api_response.Moid }}"
}
}
register: snmp_policy
02-23-2024 03:26 PM
yes that was it. Thank you
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide