02-20-2024 01:28 PM
any idea why I am getting folllowing error
"msg": "API error: (400, 'HTTP Error 400: Bad Request', b'{\"code\":\"InvalidRequest\",\"message\":\"Cannot set the collection property \\'syslog.Policy.LocalClients\\'. The minimum number of elements in the collection is \\'1\\'.\",\"messageId\":\"barcelona_property_constraints_min_collection_length_validation\",\"messageParams\":{\"1\":\"syslog.Policy\",\"2\":\"LocalClients\",\"3\":1},\"traceId\":\"uQRqi9bFkQWFEavJALNWTJKVYQfw9baCbgbzxhmrnRVW-T4KXFdcPg==\"}') "
}
- name: "Create Syslog 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: /syslog/Policies
query_params:
$filter: "Name eq '{{ syslog_policy_name }}'"
api_body: |
{
"Name": "{{ syslog_policy_name }}",
"Description": "{{ syslog_policy_description }}",
"Host": "{{ syslog_hostname }}",
"Port": "{{ syslog_port }}"
}
register: syslog_policy
Solved! Go to Solution.
02-20-2024 05:49 PM
You need to specify a LocalClient and RemoteClients object
- 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: /syslog/Policies
query_params:
$filter: "Name eq 'briamorr_syslog'"
api_body: {
"Name": "briamorr_syslog",
"Description": "syslog_policy_description",
"LocalClients":[{"ObjectType":"syslog.LocalFileLoggingClient","MinSeverity":"warning"}],
"RemoteClients":[{"Type":"syslog.RemoteLoggingClient","Enabled":true,"ObjectType":"syslog.RemoteLoggingClient","Hostname":"syslog.company.local","Port":514,"Protocol":"udp","MinSeverity":"warning"},{"ObjectType":"syslog.RemoteLoggingClient","Enabled":false,"ClassId":"syslog.RemoteLoggingClient","Facility":"","Hostname":"0.0.0.0","MinSeverity":"warning","Port":514,"Protocol":"udp","VrfName":""}],
"Organization": {
"Moid": "{{ org_resp.api_response.Moid }}"
}
}
register: syslog_policy
Since it the generic rest api module with JSON payloads, easiest thing to do is walk through whatever steps you are looking to automate in the UI with chrome developer tools open and see what calls/payloads it passes and then mimic that with Ansible.
02-20-2024 05:49 PM
You need to specify a LocalClient and RemoteClients object
- 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: /syslog/Policies
query_params:
$filter: "Name eq 'briamorr_syslog'"
api_body: {
"Name": "briamorr_syslog",
"Description": "syslog_policy_description",
"LocalClients":[{"ObjectType":"syslog.LocalFileLoggingClient","MinSeverity":"warning"}],
"RemoteClients":[{"Type":"syslog.RemoteLoggingClient","Enabled":true,"ObjectType":"syslog.RemoteLoggingClient","Hostname":"syslog.company.local","Port":514,"Protocol":"udp","MinSeverity":"warning"},{"ObjectType":"syslog.RemoteLoggingClient","Enabled":false,"ClassId":"syslog.RemoteLoggingClient","Facility":"","Hostname":"0.0.0.0","MinSeverity":"warning","Port":514,"Protocol":"udp","VrfName":""}],
"Organization": {
"Moid": "{{ org_resp.api_response.Moid }}"
}
}
register: syslog_policy
Since it the generic rest api module with JSON payloads, easiest thing to do is walk through whatever steps you are looking to automate in the UI with chrome developer tools open and see what calls/payloads it passes and then mimic that with Ansible.
02-21-2024 09:27 AM
I tried using chrome devtools to creat this policy but keep getting API error. resource path was from devtools. any idea why?
- name: "Create network connectivity 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: /networkconfig/Policies
query_params:
$filter: "Name eq '{{ netcon_policy_name }}'"
api_body: |
{
"Name": "{{ netcon_policy_name }}",
"Description": "{{ netcon_policy_description }}",
"Organization": {
"Moid": "{{ intersight_org.api_response.Moid }}"
},
"AlternateIpv4dnsServer": "0.0.0.0",
"EnableDynamicDns": "false",
"EnableIpv4dnsFromDhcp": "false",
"EnableIpv6": "false",
"Tags": [{"Key": "configmode", "Value": "ansible"}, {"Key": "prefix", "Value": "{{ prefix }}"}]
}
register: netcon_policy
02-21-2024 02:48 PM
ok got it working with this
- name: "Create network connectivity 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: /networkconfig/Policies
query_params:
$filter: "Name eq '{{ netcon_policy_name }}'"
api_body:
{
"Name": "{{ netcon_policy_name }}",
"Description": "{{ netcon_policy_description }}",
"Organization": {
"Moid": "{{ intersight_org.api_response.Moid }}"
},
"PreferredIpv4dnsServer": "{{ primary_dns_mgmt }}",
"AlternateIpv4dnsServer": "{{ secondary_dns_mgmt }}",
"Tags": [{"Key": "configmode", "Value": "ansible"}, {"Key": "prefix", "Value": "{{ prefix }}"}]
}
register: netcon_policy
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