I made an Ansible play book that loops through a .yaml file and adds descriptions to interfaces. The problem is after every set command Ansible commits, waits for the commit then configures the next interface. If I run this on a VC with 10 members it will take for ever. Any one know how to make the playbook commit only after all changes have been made?
---
- name: Change configuration using junos_config module
hosts: test
connection: local
gather_facts: no
tasks:
- include_vars: /home/ansible/interfaces.yaml
- name: Change description on interfaces based on a list of variable
junos_config:
lines:
- "set interfaces {{ item.name }} description \"{{ item.description }}\""
comment: "Update description of interface {{ item.name }}"
with_items: "{{ interfaces }}"
register: result
- debug: var=result
I changed the play book which now looks like this:
---
- name: Change configuration using junos_config module
hosts: test
connection: local
gather_facts: no
tasks:
- include_vars: /home/ansible/playbook-core/interfaces.yaml
- name: Change description on interfaces based on a list of variable
junos_config:
lines:
- "{{ lines_template }}"
- "set interfaces {{ item.name }} description \"{{ item.description }}\""
comment: "Update description of port"
vars:
lines_template: "[ {% for interface in interfaces %}'set interfaces {{ item.name }} description \"{{ item.description }}\"',{% endfor %} ]"
with_items: "{{ interfaces }}"
register: result
- debug: var=result
And when I run it I get an error:
An exception occurred during task execution. To see the full traceback, use -
vvv. The error was: TypeError: sequence item 0: expected string, list found
failed: [10.63.255.71] (item={u'name': u'ge-0/0/1', u'description': u'Set by
ansible'}) => {"changed": false, "item": {"description": "Set by ansible",
"name": "ge-0/0/1"}, "module_stderr": "Traceback (most recent ca
ll last):\n File \"/tmp/ansible_wVNymo/ansible_module_junos_config.py\",
line 402, in <module>\n main()\n File
\"/tmp/ansible_wVNymo/ansible_module_junos_config.py\", line 371, in main\n
diff = configure_device(module, warnings, candidate)\n File
\"/tmp/ansible_wVNymo/ansible_module_junos_config.py\", line 293, in
configure_device\nreturn load_config(module, candidate, warnings, **kwargs)\n
File \"/tmp/ansible_wVNy
mo/ansible_modlib.zip/ansible/module_utils/junos.py\", line 199, in
load_config\nTypeError: sequence item 0: expected string, list found\n",
"module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}