ansible - Ansible playbook 可在缺少时在 IOS 设备上添加本地帐户
问题描述
我正在尝试为 Cisco IOS 设备创建 Ansible 剧本,以检查设备上是否存在本地用户帐户。如果它存在什么都不做,但如果它不存在,我想添加它。
以下是我所拥有的,但我需要条件检查方面的帮助,即检查寄存器值的最佳方法是什么,如果 rsitadmin 存在于其中,则不执行任何操作,否则将此命令发送到设备用户名 {{user}} secret {{经过}}。
如果缺少任务添加 RSITADMIN 不起作用,但这是我要检查的摘要。
我也使用 src 参数尝试了这个 jinja 模板,但没有帮助。
{% if 'rsitadmin' in ACCOUNT %}
{% else %}
username {{user}} secret {{pass}}
{% endif %}
---
- name: Add RSITADMIN Account if missing
hosts: LAB
vars_files:
- rsitadmin.yml
gather_facts: false
connection: local
tasks:
- name: Check if RSITADMIN account exist
ios_command:
commands: sh run | s username rsitadmin
register: ACCOUNT
- name: Print RSITADMIN account details
debug:
var=ACCOUNT.stdout
- name: Add RSITADMIN if missing
ios_config:
lines: username {{user}} secret {{pass}}
when: "'rsitadmin' in ACCOUNT"
解决方案
这对我有用:
- name: Configure RSITADMIN Account on devices its missing
ios_config:
lines:
- username {{user}} secret {{pass}}
save_when: changed
when: ACCOUNT.stdout[0] is not search ("username rsitadmin")
推荐阅读
- python - 在 pyspark 中对流数据进行分组
- python - 用于 PDF 到 Excel 的 Python 和 PDFPlumber
- xamarin - 具有绑定问题的 Xamarin 表单 FlyoutPage
- javascript - 如何在 React boostrap 中使用单选按钮
- javascript - 使用 onclick 锚标记上的警报框内的链接
- amazon-web-services - AWS SSM 作为 Terraform 中任务的 valueFrom 不起作用
- flutter - 尝试在颤动中的标签栏中的标签之间添加垂直分隔线
- c++ - 使用 cmake 和 Qt Creator 获取可执行的 EXE
- dictionary - 使用传单按距离搜索标记
- python - pandas 按 timedelta64[ns] 列加入连续行分组