我有一个名为的清单文件inventory.ini
,其中仅包含:
10.0.0.4
10.0.0.5
我想在我的剧本中的变量下使用此处列出的 IP ip_address
:
- name: Import & load configuration file into PAN-OS
hosts: localhost
connection: local
gather_facts: False
vars:
ip_address: "{{ SOMETHING-GOES-HERE }}"
username: "#{PALOS_USERNAME}#"
password: "#{PALOS_PASSWORD}#"
config_file: ""
load_file: ""
roles:
- role: PaloAltoNetworks.paloaltonetworks
tasks:
- name: wait for reboot
panos_check:
ip_address: "{{ ip_address }}"
username: "{{ username }}"
password: "{{ password }}"
interval: 5
timeout: 900
- name: import configuration file into PAN-OS
panos_import:
ip_address: "{{ ip_address }}"
username: "{{ username }}"
password: "{{ password }}"
file: "{{ config_file }}"
category: "configuration"
我曾尝试使用{{ inventory_hostname }}
,但这反而带回来了localhost
。我也试过使用{{ ansible_host }}
,但这又带回来了127.0.0.1
有谁知道我如何使用清单中列出的 IP 代替变量,因为它在每个部署中循环?
请注意,我是这样运行剧本的:
ansible-playbook panos-config.yml -i inventory.ini --extra-vars "config_file=./xml-config/asdf.xml load_file=asdf.xml" -vvv
Ansible 版本是 2.8.0
原来我需要将 更改hosts
为all
,并留{{ ansible_host }}
在ip_address
变量字段中。IP 从清单文件中提取并部署良好。像这样:
- name: Import & load configuration file into PAN-OS
hosts: all
connection: local
gather_facts: False
vars:
ip_address: "{{ ansible_host }}"
username: "#{PALOS_USERNAME}#"
password: "#{PALOS_PASSWORD}#"
config_file: ""
load_file: ""
roles:
- role: PaloAltoNetworks.paloaltonetworks
tasks:
- name: wait for reboot
panos_check:
ip_address: "{{ ip_address }}"
username: "{{ username }}"
password: "{{ password }}"
interval: 5
timeout: 900
- name: import configuration file into PAN-OS
panos_import:
ip_address: "{{ ip_address }}"
username: "{{ username }}"
password: "{{ password }}"
file: "{{ config_file }}"
category: "configuration"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句