From dfe5b7dba1b5a1f221078198514a96cfd551a731 Mon Sep 17 00:00:00 2001 From: Sagi Shnaidman Date: Thu, 11 Apr 2019 09:10:12 +0300 Subject: [PATCH] Create libvirt nodes dynamically Change-Id: I46d7c8362ec5026fb5061bebb1b7b5cb4f330fcf --- .../overcloud/tasks/libvirt_nodepool.yml | 106 +----------------- .../setup/overcloud/tasks/register_vm.yml | 48 ++++++++ .../overcloud/templates/zuul-hosts.yaml.j2 | 2 + 3 files changed, 52 insertions(+), 104 deletions(-) create mode 100644 roles/libvirt/setup/overcloud/tasks/register_vm.yml diff --git a/roles/libvirt/setup/overcloud/tasks/libvirt_nodepool.yml b/roles/libvirt/setup/overcloud/tasks/libvirt_nodepool.yml index dfcfbfa95..63ee25e5c 100644 --- a/roles/libvirt/setup/overcloud/tasks/libvirt_nodepool.yml +++ b/roles/libvirt/setup/overcloud/tasks/libvirt_nodepool.yml @@ -171,110 +171,8 @@ uri: "{{ libvirt_uri }}" with_items: "{{ overcloud_nodes }}" -## need to find a way to make these next tasks generic - -- name: Get libvirt nodepool IP addresses - script: "get-domain-ip.sh subnode-0" - register: "subnode_0_ip_result" - until: "subnode_0_ip_result is success" - retries: "{{ libvirt_wait_retries }}" - delay: "{{ libvirt_wait_delay }}" - -- name: Set_fact for undercloud ip - set_fact: - subnode_0_ip: "{{ subnode_0_ip_result.stdout_lines[0] }}" - cacheable: true - -- name: Wait until ssh is available - wait_for: - host: "{{ subnode_0_ip }}" - state: started - port: 22 - timeout: 600 - -- name: Add subnode-0 to inventory - add_host: - name: subnode-0 - groups: subnodes - ansible_host: "{{ subnode_0_ip }}" - ansible_fqdn: "{{ subnode_0_ip }}" - ansible_user: zuul - subnode_private_ip: "{{ subnode_0_ip }}" - subnode_public_ip: "{{ subnode_0_ip }}" - ansible_python_interpreter: "{{ python_interpreter|default('/usr/bin/python') }}" - -- name: Add subnode-0 to known_hosts - known_hosts: - name: "{{ subnode_0_ip }}" - key: "{{ lookup('pipe', 'ssh-keyscan - -t ecdsa-sha2-nistp256 ' + subnode_0_ip) }}" - -- name: Set hostname correctly for subnode-0 - delegate_to: subnode-0 - shell: > - echo "127.0.0.1 subnode-0 localhost" > /etc/hosts; - echo "HOSTNAME=subnode-0" >> /etc/sysconfig/network; - echo "subnode-0" > /etc/hostname; - hostnamectl set-hostname subnode-0; - {% if custom_nameserver is defined and custom_nameserver %} - echo "nameserver {{ custom_nameserver }} " >> /etc/resolv.conf; - echo "append domain-name-servers {{ custom_nameserver }};" >> /etc/dhcp/dhclient.conf - {% endif %} - become: true - -- name: Get libvirt nodepool IP addresses - script: "get-domain-ip.sh subnode-1" - register: "subnode_1_ip_result" - until: "subnode_1_ip_result is success" - retries: "{{ libvirt_wait_retries }}" - delay: "{{ libvirt_wait_delay }}" - -- name: Set_fact for undercloud ip - set_fact: - subnode_1_ip: "{{ subnode_1_ip_result.stdout_lines[0] }}" - cacheable: true - -- name: Wait until ssh is available - wait_for: - host: "{{ subnode_1_ip }}" - state: started - port: 22 - timeout: 600 - -- name: dump nodepool node ip's address to disk - shell: > - echo "{{ subnode_0_ip }},{{ subnode_1_ip }}" > "{{ working_dir }}/nodepool_ips"; - delegate_to: localhost - -- name: Add subnode-1 to inventory - add_host: - name: subnode-1 - groups: subnodes - ansible_host: "{{ subnode_1_ip }}" - ansible_fqdn: "{{ subnode_1_ip }}" - ansible_user: zuul - subnode_private_ip: "{{ subnode_1_ip }}" - subnode_public_ip: "{{ subnode_1_ip }}" - ansible_python_interpreter: "{{ python_interpreter|default('/usr/bin/python') }}" - -- name: Add subnode-1 to known_hosts - known_hosts: - name: "{{ subnode_1_ip }}" - key: "{{ lookup('pipe', 'ssh-keyscan - -t ecdsa-sha2-nistp256 ' + subnode_1_ip) }}" - -- name: Set hostname correctly for subnode-1 - delegate_to: subnode-1 - shell: > - echo "127.0.0.1 subnode-1 localhost" > /etc/hosts; - echo "HOSTNAME=subnode-1" >> /etc/sysconfig/network; - echo "subnode-1" > /etc/hostname; - hostnamectl set-hostname subnode-1; - {% if custom_nameserver is defined and custom_nameserver %} - echo "nameserver {{ custom_nameserver }} " >> /etc/resolv.conf; - echo "append domain-name-servers {{ custom_nameserver }};" >> /etc/dhcp/dhclient.conf - {% endif %} - become: true +- include_tasks: register_vm.yml + with_items: "{{ overcloud_nodes }}" - name: Create inventory suitable for zuul-jobs/multinode template: diff --git a/roles/libvirt/setup/overcloud/tasks/register_vm.yml b/roles/libvirt/setup/overcloud/tasks/register_vm.yml new file mode 100644 index 000000000..8af2515a2 --- /dev/null +++ b/roles/libvirt/setup/overcloud/tasks/register_vm.yml @@ -0,0 +1,48 @@ +- name: Get libvirt nodepool IP addresses + script: "get-domain-ip.sh {{ item.name }}" + register: "ip_result" + until: "ip_result is success" + retries: "{{ libvirt_wait_retries }}" + delay: "{{ libvirt_wait_delay }}" + +- name: Set_fact for undercloud ip + set_fact: + "{{ item.name.replace('-', '_') }}_ip": "{{ ip_result.stdout_lines[0] }}" + cacheable: true + +- name: Wait until ssh is available + wait_for: + host: "{{ ip_result.stdout_lines[0] }}" + state: started + port: 22 + timeout: 600 + +- name: Add {{ item.name }} to inventory + add_host: + name: "{{ item.name }}" + groups: subnodes + ansible_host: "{{ ip_result.stdout_lines[0] }}" + ansible_fqdn: "{{ ip_result.stdout_lines[0] }}" + ansible_user: zuul + subnode_private_ip: "{{ ip_result.stdout_lines[0] }}" + subnode_public_ip: "{{ ip_result.stdout_lines[0] }}" + ansible_python_interpreter: "{{ python_interpreter|default('/usr/bin/python') }}" + +- name: Add {{ item.name }} to known_hosts + known_hosts: + name: "{{ ip_result.stdout_lines[0] }}" + key: "{{ lookup('pipe', 'ssh-keyscan + -t ecdsa-sha2-nistp256 ' + ip_result.stdout_lines[0]) }}" + +- name: Set hostname correctly for {{ item.name }} + delegate_to: "{{ item.name }}" + shell: > + echo "127.0.0.1 {{ item.name }} localhost" > /etc/hosts; + echo "HOSTNAME={{ item.name }}" >> /etc/sysconfig/network; + echo "{{ item.name }}" > /etc/hostname; + hostnamectl set-hostname {{ item.name }}; + {% if custom_nameserver is defined and custom_nameserver %} + echo "nameserver {{ custom_nameserver }} " >> /etc/resolv.conf; + echo "append domain-name-servers {{ custom_nameserver }};" >> /etc/dhcp/dhclient.conf + {% endif %} + become: true diff --git a/roles/libvirt/setup/overcloud/templates/zuul-hosts.yaml.j2 b/roles/libvirt/setup/overcloud/templates/zuul-hosts.yaml.j2 index f08e6b3ce..6b3e263f5 100644 --- a/roles/libvirt/setup/overcloud/templates/zuul-hosts.yaml.j2 +++ b/roles/libvirt/setup/overcloud/templates/zuul-hosts.yaml.j2 @@ -24,6 +24,7 @@ all: public_ipv4: "{{ subnode_0_ip }}" region: libvirt public_ipv6: null +{% if subnode_1_ip is defined %} secondary: ansible_connection: ssh ansible_host: "{{ subnode_1_ip }}" @@ -39,3 +40,4 @@ all: public_ipv4: "{{ subnode_1_ip }}" region: libvirt public_ipv6: null +{% endif %}