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 role to deploy 17.1 env for adoption #2297

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
113 changes: 113 additions & 0 deletions deploy-osp-adoption.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
# Purpose of this playbook:
# This playbook deploy OSP 17.1 on previously created
# infra for adoption. The main goal of this playbook
# is to be called as a standalone piece of a bigger
# job, mostly in the adoption context.
#
# You would typically run this playbook after the
# "create-infra.yml"

- name: Deploy 17.1 for adoption
hosts: 'localhost'
lewisdenny marked this conversation as resolved.
Show resolved Hide resolved
gather_facts: true
vars:
cifmw_basedir: "{{ ansible_user_dir }}/ci-framework-data"
_adoption_source_scenario_file: >-
{{
[cifmw_adoption_source_scenario_path,
cifmw_architecture_scenario ~ '.yaml'] | path_join
}}
_target_host: "{{ cifmw_target_host | default('localhost') }}"
tasks:
- name: Inherit from parent scenarios if needed
ansible.builtin.include_tasks:
file: "ci/playbooks/tasks/inherit_parent_scenario.yml"

- name: Ensure networking data is loaded
ansible.builtin.include_role:
name: networking_mapper
tasks_from: load_env_definition.yml
apply:
delegate_to: "{{ _target_host }}"

- name: Load source adoption scenario
ansible.builtin.include_vars:
file: "{{ _adoption_source_scenario_file }}"
name: cifmw_adoption_osp_deploy_scenario

- name: Gather ansible_user_id from {{ _target_host }}
delegate_to: "{{ _target_host }}"
ansible.builtin.setup:
gather_subset:
- user_id
- user_dir

- name: Read inventory groups
delegate_to: "{{ _target_host }}"
ansible.builtin.slurp:
path: "{{ ansible_user_dir }}/ci-framework-data/reproducer-inventory/all-group.yml"
register: "_all_groups"

- name: Generate groups
vars:
_parsed_all_groups: "{{ _all_groups['content'] | b64decode | from_yaml }}"
block:
- name: Read groups inventory
delegate_to: "{{ _target_host }}"
vars:
_group_name: "{{ item.key[:-1] }}"
_path_inventories: "{{ ansible_user_dir }}/ci-framework-data/reproducer-inventory"
ansible.builtin.slurp:
path: "{{ _path_inventories }}/{{ _group_name }}-group.yml"
register: _reproducer_inventory_files
loop: >-
{{
_parsed_all_groups.all.children | dict2items
}}

- name: Set groups fact
when: "'all' != _group_name"
vars:
_content: "{{ _inventory_file.content | b64decode | from_yaml }}"
_group_name: "{{ _content | list | first }}"
_nodes: "{{ _content[_group_name]['hosts'].keys() }}"
_group_nodes: >-
{%- set group = {} -%}
{%- set _ = group.update({_group_name: _nodes}) -%}
{{ group }}
ansible.builtin.set_fact:
_vm_groups: >-
{{ _vm_groups | default({}) | combine(_group_nodes) }}
loop: "{{ _reproducer_inventory_files.results }}"
loop_control:
loop_var: "_inventory_file"

- name: Gather ansible_user_id from playbook target for hooks
ansible.builtin.setup:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This task name Gather ansible_user_id from controller for hooks is misleading. The ansible.builtin.setup will target the playbook target, as it's not delegated, meaning it will collect the facts you ask to collect from localhost only. If you want to collect the facts from the controller you need to delegate the task to that host.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed the task name, it was doing the right thing, but the description was wrong

Copy link
Contributor

@bogdando bogdando Oct 15, 2024

Choose a reason for hiding this comment

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

I am late to the party, albeit my question is likely related to the ci framework design, not this implementation that follows it. Why do we need to make ansible parsing other ansible/t-h-t objects from yaml files, instead of using direct inputs?

gather_subset:
- user_id
- user_dir

- name: Ensure parameters folder exists
ansible.builtin.file:
path: "{{ cifmw_basedir }}/artifacts/parameters"
state: "directory"

- name: Save variables for use with hooks
vars:
_content:
cifmw_adoption_osp_deploy_ntp_server: "{{ cifmw_adoption_osp_deploy_ntp_server }}"
cifmw_adoption_source_scenario_path: "{{ cifmw_adoption_source_scenario_path }}"
cifmw_adoption_osp_deploy_scenario: "{{ cifmw_adoption_osp_deploy_scenario }}"
_vm_groups: "{{ _vm_groups }}"
ansible.builtin.copy:
dest: "{{ cifmw_basedir }}/artifacts/parameters/adoption_osp.yml"
content: "{{ _content | to_nice_yaml }}"
- name: Set inventory_file for localhost to use with hooks
ansible.builtin.set_fact:
inventory_file: "{{ hostvars[_target_host]['inventory_file'] }}"

cescgina marked this conversation as resolved.
Show resolved Hide resolved
- name: Deploy source osp environment
ansible.builtin.import_role:
name: "adoption_osp_deploy"
2 changes: 2 additions & 0 deletions docs/dictionary/en-custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ dnsdata
dnsmasq
dockerfile
dryrun
dts
ecdsa
edecb
edploy
Expand Down Expand Up @@ -516,6 +517,7 @@ uhv
uidmap
unclaim
undefine
undercloud
unittest
unmanaged
untagged
Expand Down
160 changes: 160 additions & 0 deletions hooks/playbooks/adoption_deploy_ceph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
---
# Copyright Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

- name: Deploy ceph for 17.1 deployment
hosts: "{{ cifmw_target_host | default('localhost') }}"
tasks:
- name: Gather ansible_user_dir from undercloud
delegate_to: "osp-undercloud-0"
ansible.builtin.setup:
gather_subset:
- user_dir

- name: Deploy 17.1 ceph
vars:
_cifmw_basedir_undercloud: >-
{{
[ansible_user_dir,
'ci-framework-data'
] | path_join
}}
stack: >-
{{
cifmw_adoption_osp_deploy_scenario.stacks[stack_index | int]
}}
_overcloud_name: >-
cescgina marked this conversation as resolved.
Show resolved Hide resolved
{{
stack.stackname
}}
_roles_file: >-
{{
[cifmw_adoption_source_scenario_path,
stack.roles_file
] | path_join
}}
_roles_file_dest: >-
{{
[ansible_user_dir,
'roles_' ~ _overcloud_name ~ '.yaml'
] | path_join
}}
_network_data_file_dest: >-
{{
[ansible_user_dir,
'network_data_' ~ _overcloud_name ~ '.yaml'
] | path_join
}}
_ceph_osd_spec_file: >-
{{
[cifmw_adoption_source_scenario_path,
stack.ceph_osd_spec_file
] | path_join
}}
_ceph_osd_spec_file_name: "{{ _ceph_osd_spec_file | basename }}"
_ceph_osd_spec_file_dest: >-
{{
[ansible_user_dir,
_ceph_osd_spec_file_name
] | path_join
}}
_cloud_domain: "{{ cifmw_adoption_osp_deploy_scenario.cloud_domain }}"
_source_cmd: "source {{ ansible_user_dir }}/stackrc"
block:
- name: Copy ceph osd file
delegate_to: "osp-undercloud-0"
ansible.builtin.copy:
Copy link
Collaborator

Choose a reason for hiding this comment

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

File manipulations without explicitly setting the mode will cause linter issues. iirc it's one of the rules we disabled, so no problem for now, but at some point someone will need to touch this freshly added code to make it complaint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, I haven't thought about this, I think I added the mode to all the tasks now

src: "{{ _ceph_osd_spec_file }}"
dest: "{{ _ceph_osd_spec_file_dest }}"
mode: "0644"

- name: Copy roles file
delegate_to: "osp-undercloud-0"
ansible.builtin.copy:
src: "{{ _roles_file }}"
dest: "{{ _roles_file_dest }}"
mode: "0644"

- name: Ensure ceph_spec file does not exist
delegate_to: "osp-undercloud-0"
ansible.builtin.file:
path: "{{ ansible_user_dir }}/ceph_spec.yaml"
state: absent

- name: Generate ceph_spec file
delegate_to: "osp-undercloud-0"
vars:
_ceph_spec_cmd: >-
openstack overcloud ceph spec
{{ ansible_user_dir }}/config_download_{{ _overcloud_name }}.yaml
--tld {{ _cloud_domain }}
--osd-spec {{ _ceph_osd_spec_file_dest }}
--roles-data {{ _roles_file_dest }}
-o {{ansible_user_dir}}/ceph_spec.yaml
cifmw.general.ci_script:
chdir: "{{ ansible_user_dir }}"
output_dir: "{{ _cifmw_basedir_undercloud }}/artifacts"
script: "{{ _source_cmd }}; {{ _ceph_spec_cmd }}"

- name: Ensure deployed_ceph file does not exist
delegate_to: "osp-undercloud-0"
ansible.builtin.file:
path: "{{ ansible_user_dir }}/deployed_ceph.yaml"
state: absent

- name: Gather nodes for stack {{ _overcloud_name }}
when: group.key is in _hostname_map_translation
vars:
_hostname_map_translation: >-
{{
cifmw_adoption_osp_deploy_scenario.hostname_groups_map |
ansible.utils.keep_keys(target=stack.stack_nodes)
}}
ansible.builtin.set_fact:
_tripleo_nodes: >-
{{
_tripleo_nodes | default([]) +
group.value
}}
loop: "{{ _vm_groups | dict2items }}"
loop_control:
loop_var: group
label: "{{ group.key }}"

- name: Install packages needed for ceph deployment on the overcloud nodes
become: true
delegate_to: "{{ item }}"
ansible.builtin.dnf:
name:
- lvm2
- jq
state: present
loop: "{{ _tripleo_nodes }}"

- name: Deploy ceph
delegate_to: "osp-undercloud-0"
vars:
_ceph_deploy_cmd: >-
openstack overcloud ceph deploy
--tld {{ _cloud_domain }}
--ntp-server {{ cifmw_adoption_osp_deploy_ntp_server }}
--ceph-spec ceph_spec.yaml
--network-data {{ _network_data_file_dest }}
--cephadm-default-container
--output {{ ansible_user_dir }}/deployed_ceph.yaml
cifmw.general.ci_script:
chdir: "{{ ansible_user_dir }}"
output_dir: "{{ _cifmw_basedir_undercloud }}/artifacts"
script: "{{ _source_cmd }}; {{ _ceph_deploy_cmd }}"
57 changes: 57 additions & 0 deletions roles/adoption_osp_deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# adoption_osp_deploy

Deploy OSP 17.1 environment for adoption based on DTs.

## Privilege escalation

`become` - Required in:
- `login_registries`: For running subscription manager if needed,
install packages and podman login as root.
- `prepare_overcloud`: For setting up repositories, installing packages,
create folders in /etc and running os-net-config.
- `prepare_undercloud`: For setting up repositories, installing packages,
create folders in /etc and running os-net-config.


## Parameters
* `cifmw_adoption_osp_deploy_ntp_server`: (String) NTP server to use in the 17.1
deployment. Defaults to `pool.ntp.org`
* `cifmw_adoption_osp_deploy_repos`: (List) List of 17.1 repos to enable. Defaults to
`[rhel-9-for-x86_64-baseos-eus-rpms, rhel-9-for-x86_64-appstream-eus-rpms, rhel-9-for-x86_64-highavailability-eus-rpms, openstack-17.1-for-rhel-9-x86_64-rpms, fast-datapath-for-rhel-9-x86_64-rpms, rhceph-6-tools-for-rhel-9-x86_64-rpms]`
* `cifmw_adoption_osp_deploy_stopper`: (String) Step at which to stop the run. See `Break point` section below for possible values.
* `cifmw_adoption_osp_deploy_scenario`: (Dict) Define the parameter to
configure the OSP17.1 deployment.

### Break point

You can also stop the automated deploy by setting
`cifmw_adoption_osp_deploy_stopper`
parameter to a specific value.

Break point names are built using either `undercloud` or `overcloud`,
and the code currently supports the following seven different stoppers:

- Before calling pre undercloud hook: `before_pre_hook_undercloud`
- Before deploying undercloud: `before_deploy_undercloud`
- After deploying undercloud: `after_deploy_undercloud`
- After calling post undercloud hook: `after_post_hook_undercloud`
- Before calling pre overcloud hook: `before_pre_hook_overcloud`
- Before deploying overcloud: `before_deploy_overcloud`
- After deploying overcloud: `after_deploy_overcloud`

## Examples
cescgina marked this conversation as resolved.
Show resolved Hide resolved

```YAML
- name: Deploy source osp environment
vars:
cifmw_adoption_osp_deploy_scenario:
undercloud:
config:
- section: DEFAULT
option: undercloud_hostname
value: undercloud.localdomain
stacks:
name: overcloud
ansible.builtin.import_role:
name: "adoption_osp_deploy"
```
27 changes: 27 additions & 0 deletions roles/adoption_osp_deploy/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# Copyright Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


# All variables intended for modification should be placed in this file.
# All variables within this role should have a prefix of "cifmw_adoption_osp_deploy"
cifmw_adoption_osp_deploy_ntp_server: "pool.ntp.org"
cifmw_adoption_osp_deploy_repos:
- rhel-9-for-x86_64-baseos-eus-rpms
- rhel-9-for-x86_64-appstream-eus-rpms
- rhel-9-for-x86_64-highavailability-eus-rpms
- openstack-17.1-for-rhel-9-x86_64-rpms
- fast-datapath-for-rhel-9-x86_64-rpms
- rhceph-6-tools-for-rhel-9-x86_64-rpms
Loading