From 28e2e387774735755f031f5486cfdd8738373105 Mon Sep 17 00:00:00 2001 From: Asma Syed Hameed Date: Fri, 3 Apr 2020 13:12:44 +0530 Subject: [PATCH] Add support for virtual uc on first node --- add_undercloud_to_inventory.yml | 5 ++ prepare_nic_configs.yml | 2 +- tasks/load_instackenv.yml | 25 ++++++++- templates/virtual_uc_ssh_config.yml.j2 | 10 ++++ virtual_undercloud.yml | 78 ++++++++++++++++++++------ 5 files changed, 102 insertions(+), 18 deletions(-) create mode 100644 templates/virtual_uc_ssh_config.yml.j2 diff --git a/add_undercloud_to_inventory.yml b/add_undercloud_to_inventory.yml index adb5c0c4..5bfa59fd 100644 --- a/add_undercloud_to_inventory.yml +++ b/add_undercloud_to_inventory.yml @@ -8,6 +8,7 @@ vars: hostname: "{{ undercloud_hostname }}" user: "stack" + - name: add undercloud_host to inventory file add_host: name: "undercloud" @@ -16,15 +17,19 @@ ansible_user: "stack" ansible_ssh_private_key_file: "{{ ansible_ssh_key }}" ansible_python_interpreter: "{{ python_interpreter }}" + - name: generate inventory file template: dest: "{{ infrared_hosts_dir }}/{{ inventory_file_name }}" src: inventory.j2 + - name: update inventory file symlink file: dest: "{{ infrared_hosts_file }}" state: link src: "{{ inventory_file_name }}" + force: true + - name: copy keys copy: src: "~/.ssh/id_rsa.pub" diff --git a/prepare_nic_configs.yml b/prepare_nic_configs.yml index d396ccf6..fcde5d57 100644 --- a/prepare_nic_configs.yml +++ b/prepare_nic_configs.yml @@ -2,7 +2,7 @@ - hosts: localhost vars: undercloud_host: "{{ groups.undercloud|first }}" - machine_type: "{{ (lab_name == 'scale') | ternary(undercloud_hostname.split('.')[0].split('-')[3], undercloud_hostname.split('.')[0].split('-')[2]) }}" + machine_type: "{{ (lab_name == 'scale') | ternary(instackenv_content.nodes[0].pm_addr.split('.')[0].split('-')[4], instackenv_content.nodes[0].pm_addr.split('.')[0].split('-')[3]) }}" tasks: - name: get subnet mask shell: | diff --git a/tasks/load_instackenv.yml b/tasks/load_instackenv.yml index 05337e49..30bd767b 100644 --- a/tasks/load_instackenv.yml +++ b/tasks/load_instackenv.yml @@ -49,10 +49,33 @@ - name: set undercloud hostname set_fact: undercloud_hostname: "{{ undercloud_host }}" + instack_firstnode: "{{ (instackenv_content.nodes[0].pm_addr | replace('mgmt-','') | replace('-drac', '')) }}" - name: set overcloud_instackenv content set_fact: - oc_instackenv_content: "{{ instackenv_content }}" + oc_instackenv_content: | + {% set a=instackenv_content.pop('nodes') %} + {{ instackenv_content | combine({'nodes': a|difference([a[0]])}, recursive=True) }} + + - include_tasks: tasks/copykeys.yml + vars: + hostname: "{{ instack_firstnode }}" + ssh_user: "root" + + - include_tasks: tasks/get_interpreter.yml + vars: + hostname: "{{ instack_firstnode }}" + user: "root" + + - name: add hypervisor to inventory file + add_host: + name: "hypervisor" + groups: "undercloud_hypervisor" + ansible_host: "{{ instack_firstnode }}" + ansible_user: "root" + ansible_ssh_private_key_file: "{{ ansible_ssh_key }}" + ansible_python_interpreter: "{{ python_interpreter }}" + when: virtual_uc == true - name: create overcloud_instackenv.json file diff --git a/templates/virtual_uc_ssh_config.yml.j2 b/templates/virtual_uc_ssh_config.yml.j2 new file mode 100644 index 00000000..20edc786 --- /dev/null +++ b/templates/virtual_uc_ssh_config.yml.j2 @@ -0,0 +1,10 @@ +{% if virtual_uc %} +Host vmhost + User root + Hostname {{ instack_firstnode }} + +Host {{ undercloud_host }} + Hostname {{ undercloud_host }} + User cloud-user + ProxyJump vmhost +{% endif %} diff --git a/virtual_undercloud.yml b/virtual_undercloud.yml index 11f1b023..95e7b9e7 100644 --- a/virtual_undercloud.yml +++ b/virtual_undercloud.yml @@ -1,6 +1,24 @@ --- -- hosts: localhost +- hosts: undercloud_hypervisor + vars: + undercloud_node: "{{ hostvars['localhost']['instack_firstnode'] }}" tasks: + - name: check if ssh key exists + stat: + path: "{{ ansible_ssh_key }}" + register: sshkey + + - name: Generate ssh key + shell: + ssh-keygen -q -N "" -f {{ ansible_ssh_key }} + when: sshkey.stat.exists == False + + - name: install packages + include_tasks: tasks/install_packages.yml + + - name: setup infrared + include_tasks: tasks/setup_infrared.yml + - include_tasks: tasks/copykeys.yml vars: hostname: "localhost" @@ -19,35 +37,65 @@ - name: clean previous vm shell: | source {{ infrared_dir }}/.venv/bin/activate - infrared virsh --host-address 127.0.0.1 --host-key /root/.ssh/id_rsa --image-url '{{ vm_image_url }}' --topology-network virtual_uc_network --topology-nodes virtual_uc_topology:1 --host-memory-overcommit True --cleanup True + infrared virsh --host-address {{ undercloud_node }} --host-user root --host-key /root/.ssh/id_rsa --image-url '{{ vm_image_url }}' --topology-network virtual_uc_network --topology-nodes virtual_uc_topology:1 --host-memory-overcommit True --cleanup True retries: 3 ignore_errors: yes - name: create undercloud vm shell: | source {{ infrared_dir }}/.venv/bin/activate - infrared virsh --host-address 127.0.0.1 --host-key /root/.ssh/id_rsa --image-url '{{ vm_image_url }}' --topology-network virtual_uc_network --topology-nodes virtual_uc_topology:1 --host-memory-overcommit True -vvv 2>&1 | tee log_virsh1 - - - include_tasks: tasks/get_interpreter.yml - vars: - hostname: "{{ undercloud_hostname }}" - user: "cloud-user" - - - name: python interpreter - set_fact: - python_interpreter: "{{ (python_version.stderr_lines|length > 0) | ternary('/usr/libexec/platform-python', '/usr/bin/python') }}" + infrared virsh --host-address {{ undercloud_node }} --host-user root --host-key /root/.ssh/id_rsa --image-url '{{ vm_image_url }}' --topology-network virtual_uc_network --topology-nodes virtual_uc_topology:1 --host-memory-overcommit True -vvv 2>&1 | tee log_virsh1 - name: add undercloud_host to inventory file add_host: name: "undercloud" - ansible_host: "{{ undercloud_hostname }}" + groups: "baremetal,undercloud,tester" + ansible_host: "{{ undercloud_host }}" + ansible_ssh_private_key_file: /root/.ssh/id_rsa + ansible_user: "root" + + - name: copy the inventory + fetch: + src: "{{ infrared_hosts_file }}" + dest: "{{ playbook_dir }}" + +- hosts: localhost + tasks: + - name : copy the inventory + copy: + src: "{{ playbook_dir }}/hypervisor/root/.infrared/.workspaces/active/hosts" + dest: "{{ infrared_hosts_file }}" + + - name: create ssh config + template: + src: virtual_uc_ssh_config.yml.j2 + dest: "{{ ansible_user_dir }}/.ssh/config" + + - include_tasks: tasks/copykeys.yml + vars: + hostname: "{{ undercloud_host }}" + ssh_user: "root" + ansible_ssh_pass: "redhat" + + - name: add hypervisor to inventory file + add_host: + name: "hypervisor" + groups: "undercloud_hypervisor" + ansible_host: "{{ hostvars['hypervisor']['ansible_default_ipv4']['address'] }}" + ansible_user: "root" ansible_ssh_private_key_file: "{{ ansible_ssh_key }}" - ansible_user: "cloud-user" ansible_python_interpreter: "{{ python_interpreter }}" + - name: ignore errors for the task waiting for the undercloud to be available + lineinfile: + path: "{{ ansible_user_dir }}/.infrared/plugins/tripleo-undercloud/tasks/update_and_reboot.yml" + insertafter: "uc_reachable is succeeded" + line: " ignore_errors: true " + - hosts: undercloud vars: user: "stack" + undercloud_node: "{{ hostvars['localhost']['instack_firstnode'] }}" gather_facts: yes tasks: # infrared taking the dns server from the vm's /etc/resolv.conf, @@ -65,7 +113,6 @@ mode: 0644 backup: yes become: yes - - name: copy the resolv.conf copy: src: "/etc/resolv.conf" @@ -113,4 +160,3 @@ ssh-keygen -q -t rsa -f /home/{{ user }}/.ssh/id_rsa -C "" -N "" when: ssh_keys_result.stat.exists == False become: yes -