cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
286
Views
0
Helpful
3
Replies

ansible syslog policy getting error

tdubb123
Level 1
Level 1

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

 

 

 

 

 

1 Accepted Solution

Accepted Solutions

Brian Morrissey
Cisco Employee
Cisco Employee

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.

 

 

View solution in original post

3 Replies 3

Brian Morrissey
Cisco Employee
Cisco Employee

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.

 

 

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

 

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

Review Cisco Networking for a $25 gift card