0

我需要编写一个任务才能在 Juniper MX 上执行

> configure
# deactivate system scripts
# deactivate event-options
# commit and-quit

我试过(https://ansible-juniper-collection.readthedocs.io/en/latest/config.html):

- config:
    load: 'merge'
    lines:
      - deactivate system scripts
    comment: 'Ansible Upgrade - Deactivate'
    commit: true
  vars:
    ansible_connection: local

但我明白了

Failure loading the configuraton: ConfigLoadError(severity: error, bad_element: deactivate, message: error: syntax error)

RR

4

1 回答 1

0

好的,主要问题是忽略语句和配置独占

三种解决方案:

可靠:

- config:
    load: 'merge'
    lines:
      - activate system scripts
    comment: 'Ansible Upgrade - Activate'
    commit: true
    commit_empty_changes: true
    config_mode: exclusive
    ignore_warning: 
      - statement not found
  vars:
    ansible_connection: local

或 Python:

from jnpr.junos import Device
from jnpr.junos.utils.config import Config

dev = Device(host="xxx", user="xxx", password="xxx", port=22).open()

# Ignore warning in load !!!
# jnpr.junos.exception.ConfigLoadError: 
# ConfigLoadError(severity: warning, bad_element: None, message: warning: statement not found)
with Config(dev, mode='exclusive') as cu:
    cu.load('deactivate system scripts', merge=True, ignore_warning=['statement not found'])
    cu.pdiff()
    cu.commit(comment='Test Ansible deact')
    
dev.close()

或 Python:

from jnpr.junos import Device
from jnpr.junos.utils.start_shell import StartShell

dev = Device(host="xxx", user="xxx", password="xxx", port=22).open()

with StartShell(dev) as ss:
    output = ss.run("""cli -c 'configure; deactivate system scripts; commit comment "Test Ansible"'; """, timeout=30)
    print(output)

dev.close()
于 2021-11-24T14:36:37.910 回答