Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for virtual uc on first node #175

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions add_undercloud_to_inventory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
vars:
hostname: "{{ undercloud_hostname }}"
user: "stack"

- name: add undercloud_host to inventory file
add_host:
name: "undercloud"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion prepare_nic_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
25 changes: 24 additions & 1 deletion tasks/load_instackenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')) }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to give support for other labs also, since our CI is not running on these labs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to give support for other labs also, since our CI is not running on these labs

@masco can you please share the instackenv for those machines . I will add a task for it


- 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
Expand Down
10 changes: 10 additions & 0 deletions templates/virtual_uc_ssh_config.yml.j2
Original file line number Diff line number Diff line change
@@ -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 %}
76 changes: 60 additions & 16 deletions virtual_undercloud.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
---
- hosts: localhost
- hosts: undercloud_hypervisor
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"
Expand All @@ -19,35 +35,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 127.0.0.1 --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 127.0.0.1 --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,
Expand All @@ -65,7 +111,6 @@
mode: 0644
backup: yes
become: yes

- name: copy the resolv.conf
copy:
src: "/etc/resolv.conf"
Expand Down Expand Up @@ -113,4 +158,3 @@
ssh-keygen -q -t rsa -f /home/{{ user }}/.ssh/id_rsa -C "" -N ""
when: ssh_keys_result.stat.exists == False
become: yes