执行playbook后提交所有更改

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了执行playbook后提交所有更改相关的知识,希望对你有一定的参考价值。

我制作了一本Ansible游戏书,它循环遍历.yaml文件,并为界面添加说明。问题是在每个设置命令Ansible提交之后,等待提交然后配置下一个接口。如果我在拥有10个成员的VC上运行它,它将永远需要。任何人都知道如何在完成所有更改后才能使Playbook提交?

---
- 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

我改变了现在看起来像这样的剧本:

---
- 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

当我运行它时,我收到一个错误:

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):
  File "/tmp/ansible_wVNymo/ansible_module_junos_config.py", 
line 402, in <module>
    main()
  File 
"/tmp/ansible_wVNymo/ansible_module_junos_config.py", line 371, in main
    
diff = configure_device(module, warnings, candidate)
  File 
"/tmp/ansible_wVNymo/ansible_module_junos_config.py", line 293, in 
configure_device
return load_config(module, candidate, warnings, **kwargs)
  
File "/tmp/ansible_wVNy               
mo/ansible_modlib.zip/ansible/module_utils/junos.py", line 199, in 
load_config
TypeError: sequence item 0: expected string, list found
", 
"module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
答案

将循环逻辑移动到Jinja2模板:

- 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 interfaces"
  vars:
    lines_template: "[ {% for interface in interfaces %}'set interfaces {{ interface.name }} description "{{ interface.description }}"',{% endfor %} ]"

可以跳过最后的,,但似乎Ansible弥补了这一点。

上面的代码没有使用Juniper测试,但它应该产生你想要的。

以上是关于执行playbook后提交所有更改的主要内容,如果未能解决你的问题,请参考以下文章

FragmentManager 已经在执行事务。提交后何时初始化寻呼机是安全的?

更改语言环境后未调用 onConfigurationChange

配置更改后片段丢失过渡动画

kotlin-从一个片段更改多个片段的小数位

进行后续更改后如何将最后一次提交推送到 Github?

更改片段时显示 ProgressBar - Android