tripleo-quickstart/roles/tripleo-inventory/tasks/inventory.yml

184 lines
6.6 KiB
YAML

---
- when: inventory == 'all'
block:
# required for liberty based deployments
- name: copy get-overcloud-nodes.py to undercloud
template:
src: 'get-overcloud-nodes.py.j2'
dest: '{{ working_dir }}/get-overcloud-nodes.py'
mode: 0755
# required for liberty based deployments
- name: fetch overcloud node names and IPs
shell: >
source {{ working_dir }}/stackrc;
python {{ working_dir }}/get-overcloud-nodes.py
register: registered_overcloud_nodes
- name: list the overcloud nodes
debug: var=registered_overcloud_nodes.stdout
- name: fetch the undercloud ssh key
fetch:
src: '{{ working_dir }}/.ssh/id_rsa'
dest: '{{ overcloud_key }}'
flat: true
mode: 0400
# add host to the ansible group formed from its type
# novacompute nodes are added as compute for backwards compatibility
- name: add overcloud node to ansible
with_dict: '{{ registered_overcloud_nodes.stdout | default({}) }}'
add_host:
name: '{{ item.key }}'
groups: "overcloud,{{ item.key | regex_replace('overcloud-(?:nova)?([a-zA-Z0-9_]+)-[0-9]+$', '\\1') }}"
ansible_host: '{{ item.key }}'
inventory_ip: '{{ item.value }}'
ansible_user: "{{ overcloud_user | default('heat-admin') }}"
ansible_private_key_file: "{{ overcloud_key }}"
ansible_ssh_extra_args: '-F "{{ local_working_dir }}/ssh.config.ansible"'
- when: inventory == 'multinode'
block:
- name: Get subnodes
command: cat /etc/nodepool/sub_nodes_private
register: nodes
- name: Add subnode to ansible inventory
with_indexed_items: '{{ nodes.stdout_lines | default([]) }}'
add_host:
name: 'subnode-{{ item.0 + 2 }}'
groups: "overcloud"
ansible_host: '{{ item.1 }}'
inventory_ip: '{{ item.1 }}'
ansible_user: "{{ lookup('env','USER') }}"
ansible_private_key_file: "/etc/nodepool/id_rsa"
# required for regeneration of ssh.config.ansible
- name: set_fact for undercloud ip
set_fact:
undercloud_ip: "{{ hostvars['undercloud'].undercloud_ip }}"
cacheable: true
when: hostvars['undercloud'] is defined and hostvars['undercloud'].undercloud_ip is defined
- name: set_fact for virthost
set_fact:
virthost_with_private_key: "{{ 'virthost' in groups and groups['virthost']|length>0 and hostvars[groups['virthost'][0]].ansible_private_key_file is defined }}"
- when: inventory == 'extra_node'
block:
- name: Get IP of extra node in OVB stack
script: get_extra_node.py {{ working_dir }}
args:
executable: python3
register: node_ip
- name: Set fact for private supplemental ip
set_fact:
supplemental_node_ip_private: "{{ node_ip.stdout|replace('\n', '')|replace('\r', '')|trim }}"
cacheable: true
when: node_ip.stdout
- name: Add supplemental node vm to inventory
add_host:
name: supplemental
groups: supplemental
ansible_host: supplemental
ansible_fqdn: supplemental
ansible_user: '{{ supplemental_user }}'
ansible_private_key_file: '{{ extra_node_key }}'
ansible_ssh_extra_args: '-F "{{ local_working_dir }}/ssh.config.ansible"'
supplemental_node_ip: "{{ supplemental_node_ip }}"
when: supplemental_node_ip_private is defined
- name: Remove extra node
script: remove_extra_node.py {{ working_dir }}
args:
executable: python3
# readd the undercloud to reset the ansible_ssh parameters set in quickstart
- name: Add undercloud vm to inventory
add_host:
name: undercloud
ansible_host: '{{ undercloud_ip }}'
ansible_fqdn: undercloud
ansible_user: '{{ undercloud_user }}'
ansible_private_key_file: '{{ undercloud_key }}'
ansible_ssh_extra_args: '-F "{{ local_working_dir }}/ssh.config.local.ansible"'
undercloud_ip: "{{ undercloud_ip }}"
when: not virthost_with_private_key and undercloud_ip is defined
# required for regeneration of ssh.config.ansible
- name: set undercloud ssh proxy command
set_fact:
undercloud_ssh_proxy_command: "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-o ConnectTimeout=60 -i {{ hostvars[groups['virthost'][0]].ansible_private_key_file }}
{{ ssh_user }}@{{ hostvars[groups['virthost'][0]].ansible_host }}
-W {{ undercloud_ip }}:22"
cacheable: true
when: virthost_with_private_key and undercloud_ip is defined
# required for regeneration of ssh.config.ansible
- name: set undercloud ssh proxy command
set_fact:
undercloud_ssh_proxy_command: "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-o ConnectTimeout=60 -i {{ local_working_dir }}/id_rsa_virt_power
{{ ssh_user }}@{{ hostvars['localhost'].ansible_default_ipv4.address }}
-W {{ undercloud_ip }}:22"
cacheable: true
when: not virthost_with_private_key and undercloud_ip is defined
- name: set supplemental ssh proxy command
set_fact:
supplemental_ssh_proxy_command: "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-o ConnectTimeout=60 -i {{ local_working_dir }}/id_rsa_virt_power
{{ ssh_user }}@{{ hostvars[groups['virthost'][0]].ansible_host }}
-W {{ supplemental_node_ip }}:22"
cacheable: true
when: supplemental_node_ip is defined
- name: create inventory from template
delegate_to: localhost
template:
src: 'inventory.j2'
dest: '{{ local_working_dir }}/hosts'
- name: regenerate ssh config
delegate_to: localhost
template:
src: 'ssh_config.j2'
dest: '{{ local_working_dir }}/ssh.config.ansible'
mode: 0644
when: undercloud_ip is defined
- name: regenerate ssh config for ssh connections from the virthost
delegate_to: localhost
template:
src: 'ssh_config_localhost.j2'
dest: '{{ local_working_dir }}/ssh.config.local.ansible'
mode: 0644
when: undercloud_ip is defined
# just setup the ssh.config.ansible and hosts file for the virthost
- name: check for existence of identity key
delegate_to: localhost
stat: path="{{ local_working_dir }}/id_rsa_virt_power"
when: undercloud_ip is not defined
register: result_stat_id_rsa_virt_power
- name: set fact used in ssh_config_no_undercloud.j2 to determine if IdentityFile should be included
set_fact:
id_rsa_virt_power_exists: true
cacheable: true
when: undercloud_ip is not defined and result_stat_id_rsa_virt_power.stat.exists
- name: regenerate ssh config, if no undercloud has been launched.
delegate_to: localhost
template:
src: 'ssh_config_no_undercloud.j2'
dest: '{{ local_working_dir }}/ssh.config.ansible'
mode: 0644
when: undercloud_ip is not defined