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

ansible snmp policy error

tdubb123
Level 1
Level 1

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
1 Accepted Solution

Accepted Solutions

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

 

 

View solution in original post

3 Replies 3

tdubb123
Level 1
Level 1

i noticed it does not like the way these values are in the API body

#Enabled: "true"
#SnmpPort: "161",
#V2Enabled: "true",
#V3Enabled: "true",
#SysContact: "{{ SNMP_Contact }}",
#SysLocation: "{{ SNMP_Location }}"
 
any idea?

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

 

 

yes that was it. Thank you