You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's a plethora of parameters that would be nice to have in modules. In the process of wishing for this we often forget, me included, that Ansible is quite capable of handling rather complex operations using tasks. I believe the general rule is that tasks is to be preferred over adding parameters to modules, as long as using tasks is possible.
For instance your example workflow can be accomplished using the following tasks with the before and after parameters of ios_config. This is important to ensure idempotency.
tasks:
- name: Collect Interfaces with Pmap SHAPE_2M
cisco.ios.ios_command:
commands:
- "show policy-map interface |
incl ^ [A-Za-z]|Service-policy output: SHAPE_2M"
register: pmap_intfs
- name: Create List of Interfaces with Pmap SHAPE_2M
set_fact:
intfs: "{{ pmap_intfs.stdout[0] |
regex_findall('(\\S+)\\s\n') }}"
- name: Check Pmap SHAPE_2M
block:
- name: Validate and Update if Necessary
cisco.ios.ios_config:
before: |
no policy-map SHAPE_2M
{% for intf in intfs %}
interface {{ intf }}
no service-policy output SHAPE_2M
{% endfor %}
after: "{{ lookup('template', 'qos_apply.j2') }}"
replace: block
match: exact
lines:
- " class test"
- " bandwidth remaining percent 10"
- " class class-default"
- " shape average 2000000"
- " fair-queue"
- " random-detect"
parents:
- policy-map SHAPE_2M
rescue:
- name: Reapply Pmap Upon Failure
cisco.ios.ios_config:
src: qos_apply.j2
Note the rescue block which is used to reapply the policies to interfaces in case the Check Pmap task fails.
I have delibaretly used the inline way and lookup to execute the j2 templates in the before and after just to illustrate
the different possibilities.
The qos_apply.j2 template file looks pretty much like the inline template just
"reversed" like this:
{% for intf in intfs %}
interface {{ intf }}
service-policy output SHAPE_2M
{% endfor %}
Btw, I believe the service-policy is automatically removed from interfaces when issuing no policy-map SHAPE_2M, so the iteration in before is probably not necessary. However, I don't know how consistent that is across platforms and software versions so it's best to have it there just in case :)
SUMMARY
Add additional Parameters for Service-Policy to Cisco.ios.Interfaces.
ISSUE TYPE
COMPONENT NAME
Cisco.ios.interfaces
ADDITIONAL INFORMATION
Requested Parameters:
Example config snippets used in production:
An example workflow would be:
Equivalent Interface IOS commands:
The text was updated successfully, but these errors were encountered: