Ansible 库存 netapp.ontap
我刚刚开始在 Ansible 中测试我的第一个剧本,但不幸的是我在设置清单时已经失败了。我正在尝试使用模块 na_ontap_ssh_command (netapp.ontap 集合)在 NetApp 集群上运行版本命令。
该剧本适用于单个集群,但一旦我尝试设置库存文件,它就不起作用。
这有效:
---
- hosts: localhost
collections:
- netapp.ontap
name: Cluster ONTAP Version
vars:
login: &login
hostname: cluster1
username: "{{ netapp_username }}"
password: "{{ netapp_password }}"
validate_certs: true
vars_files:
- secret.yml
tasks:
- name: cli Command
netapp.ontap.na_ontap_ssh_command:
command: version
<<: *login
register: cluster_version
- name: Print Output
debug:
var: cluster_version['stdout_lines_filtered']
我尝试根据https://netapp.io/2019/07/17/running-a-playbook-against-multiple-ontap-clusters/设置剧本和清单文件,但它不起作用:
inventory.yml
cluster1
cluster2
---
- hosts: all
gather_facts: false
collections:
- netapp.ontap
name: Cluster ONTAP Version
vars:
login: &login
hostname: "{{ inventory_hostname }}"
username: "{{ netapp_username }}"
password: "{{ netapp_password }}"
validate_certs: true
vars_files:
- secret.yml
tasks:
- name: Version CLI Command
netapp.ontap.na_ontap_ssh_command:
command: version
<<: *login
connection: local
register: cluster_version
- name: Print Output
debug:
var: cluster_version['stdout_lines_filtered']
我收到的错误消息是:“需要 python paramiko 模块” 但 paramiko 已安装并适用于单个集群。
任何人都可以帮助如何设置 netapp.ontap 模块的清单吗?
尝试从任务中删除“连接:本地”,并将其移至播放关卡:
---
- hosts: all
gather_facts: false
connection: local
collections:
- netapp.ontap
name: Cluster ONTAP Version
这还有一个额外的好处,那就是不那么乏味。
我还建议确保您使用足够新的 Ansible 版本来使用模块默认值。 https://netapp.io/2022/02/15/ansible-module-defaults-the-ansible-specific-alternative-to-yaml-aliases/
这就是全部的样子
---
- hosts: all
gather_facts: false
connection: local
collections:
- netapp.ontap
name: Cluster ONTAP Version
module_defaults:
group/netapp.ontap.netapp_ontap:
hostname: "{{ inventory_hostname }}"
username: "{{ netapp_username }}"
password: "{{ netapp_password }}"
validate_certs: true
vars_files:
- secret.yml
tasks:
- name: Version CLI Command
netapp.ontap.na_ontap_ssh_command:
command: version
register: cluster_version
- name: Print Output
debug:
var: cluster_version['stdout_lines_filtered']