Fix internal_ip detection in {enroll,deploy}-dynamic

Gather facts on localhost before running them to learn the IP
address of the network_interface, which, in turn, is needed
for the default value of ironic_url.

Do not try to fetch interface information from target hosts,
best case it will fail, worst case - will provide IP information
from hosts themselves.

Change-Id: Ib884c739457fa6e4d0159441c2ae855af61c55c1
This commit is contained in:
Dmitry Tantsur 2020-09-17 11:15:07 +02:00
parent 3823944c76
commit dc57b72767
3 changed files with 14 additions and 1 deletions

View File

@ -1,4 +1,9 @@
---
- hosts: localhost
name: "Gather facts on localhost"
become: no
gather_facts: yes
- hosts: baremetal
name: "Create configuration drive files and deploy machines from inventory"
become: no

View File

@ -1,4 +1,9 @@
---
- hosts: localhost
name: "Gather facts on localhost"
become: no
gather_facts: yes
- hosts: baremetal
name: "Enroll hardware from inventory into Ironic"
become: no

View File

@ -3,7 +3,10 @@ noauth_mode: true
network_interface: "virbr0"
ans_network_interface: "{{ network_interface | replace('-', '_') }}"
internal_ip: "{{ hostvars[inventory_hostname]['ansible_' + ans_network_interface]['ipv4']['address'] }}"
# NOTE(dtantsur): dynamic playbooks are run on bare metal hosts, not on
# localhost, and the interface fact may not be available for them.
ans_interface_host: "{{ groups['target'][0] if 'target' in groups else '127.0.0.1' }}"
internal_ip: "{{ hostvars[ans_interface_host]['ansible_' + ans_network_interface]['ipv4']['address'] }}"
enable_tls: false
api_protocol: "{{ 'https' if enable_tls | bool else 'http' }}"