在 Playbook 中使用 Ansible inventory IP
Use Ansible inventory IP in Playbook
我有一个名为 inventory.ini
的清单文件,其中仅包含:
10.0.0.4
10.0.0.5
我想使用变量 ip_address
:
下我的 Playbook 中列出的 IP
- 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
,并在 ip_address
变量字段中保留 {{ ansible_host }}
。 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"
我有一个名为 inventory.ini
的清单文件,其中仅包含:
10.0.0.4
10.0.0.5
我想使用变量 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
,并在 ip_address
变量字段中保留 {{ ansible_host }}
。 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"