Create libvirt nodes dynamically

Change-Id: I46d7c8362ec5026fb5061bebb1b7b5cb4f330fcf
This commit is contained in:
Sagi Shnaidman 2019-04-11 09:10:12 +03:00
parent 71b445184c
commit dfe5b7dba1
3 changed files with 52 additions and 104 deletions

View File

@ -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:

View File

@ -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

View File

@ -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 %}