
背景知识:
- Aruba AOS8
- Ansible
- Linux
- YAML
- Python
内容简介:
Ansible是基于Python开发的,一个自动化运维的框架。控制节点(安装Ansible的主机)通过各种模块(Role)或者内置的功能组件对目标设备(Inventory)进行自动化的批量操作和部署(包括但不限于:SSH,REST API等等)。
Ansible作为 开源的自动化运维工具已经被用在越来越多的使用场景。几乎所有的可管理设备(包括网络设备、安全设备、主机、虚拟化平台等等)都已经支持Ansible。
这个文档将简单介绍Ansible的入门使用。以及利用Ansible实现Aruba MM的定期自动备份配置功能。
这里只是抛砖引玉实现了一个小的使用场景,除了自动备份配置,也可以根据实际场景实现自动配置功能。当然同样的功能 还有很多种实现方法。比如Ansible Tower(Ansible的商用版本)的Schedule功能可以很方便的实现这个功能。
我尝试了这个实验,但是没有成功,用macbook直接运行的,
ansible-playbook [core 2.12.1]
config file = None
configured module search path = [‘/Users/leo.ma/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ansible
ansible collection location = /Users/leo.ma/.ansible/collections:/usr/share/ansible/collections
executable location = /Library/Frameworks/Python.framework/Versions/3.9/bin/ansible-playbook
python version = 3.9.6 (v3.9.6:db3ff76da1, Jun 28 2021, 11:49:53) [Clang 6.0 (clang-600.0.57)]
jinja version = 3.0.3
libyaml = True
No config file found; using defaults
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)
Syntax Error while loading YAML.
did not find expected ‘-‘ indicator
The error appears to be in ‘/Users/leo.ma/onlyleo/python/aruba_python/demo_playbook.yml’: line 3, column 2, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
– hosts: all
roles:
^ here
你这个应该是语法错误,Yaml语言和Python类似,采用代码缩进来区分代码的层次的。你试试把roles和hosts保持相同的缩进。