<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: config SNMP using Ansible in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/config-snmp-using-ansible/m-p/4317064#M2225</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;Why not create a loop which iterates over a list containing the different SNMP option permutations. Something like:&lt;/P&gt;
&lt;PRE&gt;---&lt;BR /&gt;&lt;BR /&gt;- name: the_snmp_bit
  ios_config:
    lines:     
      - " snmp-server group {{ group_name }} {{ version }}  {{ security_level }} {{ item }}"
  loop:&lt;BR /&gt;    - ""
    - "context -vlan match prefix"&lt;BR /&gt;    - "read SNMPVIEW write SNMPVIEW"&lt;BR /&gt;    - "context -vlan match prefix"
&lt;BR /&gt;...&lt;/PRE&gt;
&lt;P&gt;...but then you are just hardcoding the variables into the playbook which is a bad thing. So you could create a new var file and call that:&lt;/P&gt;
&lt;PRE&gt;---

- name: get_vars
  include_vars:
    file: snmp_options.yaml

- name: the_snmp_bit
  ios_config:
    lines:     
      - " snmp-server group {{ group_name }} {{ version }}  {{ security_level }} {{ item }}"
  loop:
    - "{{ snmp_options }}"

...&lt;/PRE&gt;
&lt;P&gt;With the var snmp_options.yaml file looking like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;---
- snmp_options:&lt;BR /&gt;  - "" &lt;BR /&gt;  - "context -vlan match prefix"&lt;BR /&gt;  - "read SNMPVIEW write SNMPVIEW"&lt;BR /&gt;  - "context -vlan match prefix"&lt;BR /&gt;&lt;BR /&gt;...&lt;/PRE&gt;
&lt;P&gt;cheers,&lt;/P&gt;
&lt;P&gt;Seb.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Mar 2021 22:53:11 GMT</pubDate>
    <dc:creator>Seb Rupik</dc:creator>
    <dc:date>2021-03-31T22:53:11Z</dc:date>
    <item>
      <title>config SNMP using Ansible</title>
      <link>https://community.cisco.com/t5/controllers/config-snmp-using-ansible/m-p/4316403#M2224</link>
      <description>&lt;P&gt;Hallo,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;im trying to create a playbook for SNMP Configurations and i need your help/suggestions.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;so i want to config this 4 commands for example in one run,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;playbook:&lt;/FONT&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;- ios_config:&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;lines:&lt;/SPAN&gt;&lt;SPAN class="s1"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;- " snmp-server group {{ group_name }} {{ snmp_version }}&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;{{ security}}"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN class="s1"&gt;vars file:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;---&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;# vars file for snmp_config&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;group_name: "group_1&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;version: "V3"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;security_level: "priv"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN class="s1"&gt;this work for this command: "&lt;FONT color="#800000"&gt;smp-server group group_1 v3 priv &lt;/FONT&gt;&amp;nbsp;"&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN class="s1"&gt;but i dont know how to edit the line to be dynamic for all other options&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN class="s1"&gt;i hope you understand my question.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN class="s1"&gt;Regards,&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 13:16:14 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/config-snmp-using-ansible/m-p/4316403#M2224</guid>
      <dc:creator>Saskiaaa</dc:creator>
      <dc:date>2021-04-01T13:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: config SNMP using Ansible</title>
      <link>https://community.cisco.com/t5/controllers/config-snmp-using-ansible/m-p/4317064#M2225</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;Why not create a loop which iterates over a list containing the different SNMP option permutations. Something like:&lt;/P&gt;
&lt;PRE&gt;---&lt;BR /&gt;&lt;BR /&gt;- name: the_snmp_bit
  ios_config:
    lines:     
      - " snmp-server group {{ group_name }} {{ version }}  {{ security_level }} {{ item }}"
  loop:&lt;BR /&gt;    - ""
    - "context -vlan match prefix"&lt;BR /&gt;    - "read SNMPVIEW write SNMPVIEW"&lt;BR /&gt;    - "context -vlan match prefix"
&lt;BR /&gt;...&lt;/PRE&gt;
&lt;P&gt;...but then you are just hardcoding the variables into the playbook which is a bad thing. So you could create a new var file and call that:&lt;/P&gt;
&lt;PRE&gt;---

- name: get_vars
  include_vars:
    file: snmp_options.yaml

- name: the_snmp_bit
  ios_config:
    lines:     
      - " snmp-server group {{ group_name }} {{ version }}  {{ security_level }} {{ item }}"
  loop:
    - "{{ snmp_options }}"

...&lt;/PRE&gt;
&lt;P&gt;With the var snmp_options.yaml file looking like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;---
- snmp_options:&lt;BR /&gt;  - "" &lt;BR /&gt;  - "context -vlan match prefix"&lt;BR /&gt;  - "read SNMPVIEW write SNMPVIEW"&lt;BR /&gt;  - "context -vlan match prefix"&lt;BR /&gt;&lt;BR /&gt;...&lt;/PRE&gt;
&lt;P&gt;cheers,&lt;/P&gt;
&lt;P&gt;Seb.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 22:53:11 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/config-snmp-using-ansible/m-p/4317064#M2225</guid>
      <dc:creator>Seb Rupik</dc:creator>
      <dc:date>2021-03-31T22:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: config SNMP using Ansible</title>
      <link>https://community.cisco.com/t5/controllers/config-snmp-using-ansible/m-p/4317306#M2226</link>
      <description>&lt;P&gt;Hi Seb,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;first thanks for your replay,&lt;/P&gt;&lt;P&gt;HINT: im using ansible roles&amp;nbsp;&lt;/P&gt;&lt;P&gt;your solution will be good if i have only one group , but in my case i have two diff groups ( group_1 , group_2 )&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;is there any other solution to prevent writing the whole command ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 13:18:25 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/config-snmp-using-ansible/m-p/4317306#M2226</guid>
      <dc:creator>Saskiaaa</dc:creator>
      <dc:date>2021-04-01T13:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: config SNMP using Ansible</title>
      <link>https://community.cisco.com/t5/controllers/config-snmp-using-ansible/m-p/4317365#M2227</link>
      <description>&lt;P&gt;Hello again,&lt;/P&gt;
&lt;P&gt;How about using a dictionary instead of list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;---

- name: get_vars
  include_vars:
    file: snmp_options.yaml

- name: the_snmp_bit
  ios_config:
    lines:     
      - " snmp-server group {{ item.type }} {{ item.options }}"
  loop:
    - { type: "READ-ONLY", options: "v3 auth context vlan- match prefix" }
    - { type: "READ-WRITE", options: "v3 priv read SNMPVIEW write SNMPVIEW" }

...&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your goal is to reduce the number of commands in the playbook then you will need to hide the logic for building the SNMP parameters elsewhere. Just embedding the constructed strings in another var file will work. The more dynamic you try to make the SNMP parameter string building logic the more lines of code you will eventually end up with!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cheers,&lt;/P&gt;
&lt;P&gt;Seb.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 12:32:56 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/config-snmp-using-ansible/m-p/4317365#M2227</guid>
      <dc:creator>Seb Rupik</dc:creator>
      <dc:date>2021-04-01T12:32:56Z</dc:date>
    </item>
  </channel>
</rss>

