From dc57b72767d52077b0f31c45a6db737e28b26e7a Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 17 Sep 2020 11:15:07 +0200 Subject: [PATCH] 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 --- playbooks/deploy-dynamic.yaml | 5 +++++ playbooks/enroll-dynamic.yaml | 5 +++++ playbooks/roles/bifrost-cloud-config/defaults/main.yml | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/playbooks/deploy-dynamic.yaml b/playbooks/deploy-dynamic.yaml index aa027b408..d16b46bc1 100644 --- a/playbooks/deploy-dynamic.yaml +++ b/playbooks/deploy-dynamic.yaml @@ -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 diff --git a/playbooks/enroll-dynamic.yaml b/playbooks/enroll-dynamic.yaml index 9bad99e62..a970695b1 100644 --- a/playbooks/enroll-dynamic.yaml +++ b/playbooks/enroll-dynamic.yaml @@ -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 diff --git a/playbooks/roles/bifrost-cloud-config/defaults/main.yml b/playbooks/roles/bifrost-cloud-config/defaults/main.yml index 35a0ede0a..660b4abcf 100644 --- a/playbooks/roles/bifrost-cloud-config/defaults/main.yml +++ b/playbooks/roles/bifrost-cloud-config/defaults/main.yml @@ -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' }}"