好的,主要问题是忽略语句和配置独占
三种解决方案:
可靠:
- 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()