-
Notifications
You must be signed in to change notification settings - Fork 35
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 setup_acm_agents role #455
Draft
betoredhat
wants to merge
1
commit into
main
Choose a base branch
from
setup_agents
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+271
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
setup_acm_agents | ||
========= | ||
|
||
This role prepares agents on an on-premise inventory (whether bare metal or virtualized) for provisioning. The nodes must be accessible via Virtual Media. | ||
|
||
Requirements | ||
------------ | ||
|
||
* The nodes must be reachable via Virtual Media. | ||
* Access to an OpenShift cluster with ACM and MCE operators | ||
* Access to a valid kubeconfig file available using the `KUBECONFIG` environment variable. | ||
* AgentServiceConfig and Provisioning configured on the host cluster | ||
|
||
Role Variables | ||
-------------- | ||
|
||
The following variables can be set to customize the role behavior: | ||
|
||
### Required Variables | ||
|
||
| Variable Name | Type | Required | Default Value | Description | ||
| --------------------------------------- | --------- | -------- | -------------------------------------- | -------------- | ||
| setup_acm_agents_inventory | List | Yes | [] | Inventory of bare metal hosts. It must contain the BMC credentials. See [Usage examples](#usage-examples) | ||
| setup_acm_agents_infraenv_name | String | Yes | | Target the infrastructure environment | ||
| setup_acm_agents_inject_dns | Boolean | No | false | Enables custom DNS injection. Set to true to pass custom DNS configuration; false disables it | ||
| setup_acm_agents_inject_dns_nameserver | String | No | | Specifies the custom DNS server(s) to use when `setup_acm_agent_inject_dns` is set to true | ||
| setup_acm_agents_location_label | String | No | "" | Location label | ||
| setup_acm_agents_no_log | Boolean | No | `false` | Role's logging configuration | ||
|
||
Usage examples | ||
---------------- | ||
|
||
```yaml | ||
--- | ||
- hosts: localhost | ||
tasks: | ||
- name: Setup ACM Agents | ||
include_role: | ||
name: setup_acm_agents | ||
vars: | ||
setup_acm_agents_infraenv_name: <InfraN> | ||
setup_acm_agent_inventory: | ||
- name: <server#1> | ||
address: idrac-virtualmedia://<idrac ip>/redfish/v1/Systems/System.Embedded.1 | ||
bootMACAddress: <MAC address> | ||
username: <idrac/ilo username> | ||
password: <idrac/ilo password> | ||
- name: <server#2> | ||
address: idrac-virtualmedia://<idrac ip>/redfish/v1/Systems/System.Embedded.1 | ||
bootMACAddress: <MAC address> | ||
username: <idrac/ilo username> | ||
password: <idrac/ilo password> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
setup_acm_agents_location_label: "" | ||
setup_acm_agents_inject_dns: false | ||
setup_acm_agents_no_log: false | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
--- | ||
- name: Create a namespace for Agents | ||
community.kubernetes.k8s: | ||
api_version: v1 | ||
kind: Namespace | ||
name: "{{ setup_acm_agents_infraenv_name }}" | ||
|
||
- name: Get hub cluster pull_secret details | ||
community.kubernetes.k8s_info: | ||
api: v1 | ||
kind: Secret | ||
name: "pull-secret" | ||
namespace: openshift-config | ||
register: _setup_acm_agents_acm_pull_secret | ||
|
||
- name: Get first Master MCP | ||
community.kubernetes.k8s_info: | ||
api_version: machineconfiguration.openshift.io/v1 | ||
kind: MachineConfigPool | ||
name: master | ||
register: _setup_acm_agents_master_mcp | ||
|
||
- name: Get first Master's Machine config Pools | ||
ansible.builtin.set_fact: | ||
setup_acm_agents_acm_mc: "{{ _setup_acm_agents_master_mcp.resources[0].spec.configuration.name }}" | ||
|
||
- name: Get first Master Machine configs | ||
community.kubernetes.k8s_info: | ||
api_version: machineconfiguration.openshift.io/v1 | ||
kind: MachineConfig | ||
name: "{{ setup_acm_agents_acm_mc }}" | ||
register: _setup_acm_agents_master_mc | ||
|
||
- name: Setting config facts based on Hub Cluster configs | ||
ansible.builtin.set_fact: | ||
setup_acm_agents_sshkey: "{{ _setup_acm_agents_master_mc.resources[0].spec.config.passwd.users[0].sshAuthorizedKeys[0] | | ||
regex_replace('\n', '') }}" | ||
setup_acm_agents_pull_secret: '{{ _setup_acm_agents_acm_pull_secret.resources[0].data[".dockerconfigjson"] }}' | ||
|
||
- name: Set pull secret for Assisted installer and Cluster deployment | ||
community.kubernetes.k8s: | ||
kubeconfig: "{{ setup_acm_agents_kubeconfig_file | default(omit) }}" | ||
definition: | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: "{{ setup_acm_agents_infraenv_name }}-pull-secret" | ||
namespace: "{{ setup_acm_agents_infraenv_name }}" | ||
data: | ||
.dockerconfigjson: "{{ setup_acm_agents_pull_secret }}" | ||
type: kubernetes.io/dockerconfigjson | ||
|
||
- name: Define InfraEnv spec without kernelArguments | ||
ansible.builtin.set_fact: | ||
setup_acm_agents_infraenv_spec: | ||
agentLabels: | ||
agentclusterinstalls.extensions.hive.openshift.io/location: "{{ setup_acm_agents_location_label }}" | ||
cpuArchitecture: x86_64 | ||
ipxeScriptType: DiscoveryImageAlways | ||
nmStateConfigLabelSelector: | ||
matchLabels: | ||
infraenvs.agent-install.openshift.io: "{{ setup_acm_agents_infraenv_name }}" | ||
pullSecretRef: | ||
name: "{{ setup_acm_agents_infraenv_name }}-pull-secret" | ||
sshAuthorizedKey: "{{ setup_acm_agents_sshkey }}" | ||
|
||
- name: Define InfraEnv spec with kernelArguments | ||
ansible.builtin.set_fact: | ||
setup_acm_agents_infraenv_spec: >- | ||
{{ | ||
setup_acm_agents_infraenv_spec | combine({ | ||
"kernelArguments": [ | ||
{ | ||
"operation": "append", | ||
"value": "nameserver=" + setup_acm_agents_inject_dns_nameserver | ||
} | ||
] | ||
}, recursive=True) | ||
}} | ||
when: setup_acm_agents_inject_dns | bool | ||
|
||
- name: Create InfraEnv YAML file | ||
community.kubernetes.k8s: | ||
kubeconfig: "{{ setup_acm_agents_kubeconfig_file | default(omit) }}" | ||
definition: | ||
apiVersion: agent-install.openshift.io/v1beta1 | ||
kind: InfraEnv | ||
metadata: | ||
annotations: | ||
infraenv.agent-install.openshift.io/enable-ironic-agent: "true" | ||
labels: | ||
agentclusterinstalls.extensions.hive.openshift.io/location: "{{ setup_acm_agents_location_label }}" | ||
networkType: dhcp | ||
name: "{{ setup_acm_agents_infraenv_name }}" | ||
namespace: "{{ setup_acm_agents_infraenv_name }}" | ||
spec: "{{ setup_acm_agents_infraenv_spec }}" | ||
|
||
- name: Pause for sometime before checking for Discovery iso image. | ||
ansible.builtin.pause: | ||
seconds: 20 | ||
|
||
- name: Check if Discovery iso image is Ready | ||
community.kubernetes.k8s_info: | ||
api_version: agent-install.openshift.io/v1beta1 | ||
kind: InfraEnv | ||
kubeconfig: "{{ setup_acm_agents_kubeconfig_file | default(omit) }}" | ||
name: "{{ setup_acm_agents_infraenv_name }}" | ||
namespace: "{{ setup_acm_agents_infraenv_name }}" | ||
register: _setup_acm_agents_infraenv_info | ||
until: | ||
- _setup_acm_agents_infraenv_info != none | ||
- "'resources' in _setup_acm_agents_infraenv_info" | ||
- _setup_acm_agents_infraenv_info.resources != none | ||
- _setup_acm_agents_infraenv_info.resources | length > 0 | ||
- _setup_acm_agents_infraenv_info.resources[0].status.conditions | | ||
json_query("[?type=='ImageCreated' && status=='True']") != none | ||
- _setup_acm_agents_infraenv_info.resources[0].status.conditions | | ||
json_query("[?type=='ImageCreated' && status=='True']") | length > 0 | ||
retries: 3 | ||
delay: 20 | ||
|
||
- name: Create Secrets with creds of hardware inventory | ||
community.kubernetes.k8s: | ||
kubeconfig: "{{ setup_acm_agents_kubeconfig_file | default(omit) }}" | ||
definition: | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: "{{ bmc.name }}-creds" | ||
namespace: "{{ setup_acm_agents_infraenv_name }}" | ||
type: Opaque | ||
data: | ||
username: "{{ bmc.username | b64encode }}" | ||
password: "{{ bmc.password | b64encode }}" | ||
state: present | ||
loop: "{{ setup_acm_agents_inventory }}" | ||
loop_control: | ||
loop_var: bmc | ||
|
||
- name: Set initial annotations for BMH without installer-args | ||
ansible.builtin.set_fact: | ||
setup_acm_agents_dynamic_annotation: | ||
'inspect.metal3.io': 'disabled' | ||
|
||
- name: Add installer-args annotation in ase custom dns server is used | ||
ansible.builtin.set_fact: | ||
setup_acm_agents_dynamic_annotation: | | ||
{{ | ||
setup_acm_agents_dynamic_annotation | combine({ | ||
'bmac.agent-install.openshift.io/installer-args': | ||
'["--append-karg", "nameserver=' ~ setup_acm_agents_inject_dns_nameserver ~ '"]' | ||
}) | ||
}} | ||
when: setup_acm_agents_inject_dns | bool | ||
|
||
- name: Loop through bm_inventory and create BareMetalHost resources | ||
community.kubernetes.k8s: | ||
kubeconfig: "{{ setup_acm_agents_kubeconfig_file | default(omit) }}" | ||
definition: | ||
apiVersion: metal3.io/v1alpha1 | ||
kind: BareMetalHost | ||
metadata: | ||
annotations: "{{ setup_acm_agents_dynamic_annotation }}" | ||
labels: | ||
infraenvs.agent-install.openshift.io: "{{ setup_acm_agents_infraenv_name }}" | ||
name: "{{ bmc.name }}" | ||
namespace: "{{ setup_acm_agents_infraenv_name }}" | ||
spec: | ||
automatedCleaningMode: disabled | ||
bmc: | ||
address: "{{ bmc.address }}" | ||
credentialsName: "{{ bmc.name }}-creds" | ||
disableCertificateVerification: true | ||
bootMACAddress: "{{ bmc.bootMACAddress }}" | ||
customDeploy: | ||
method: start_assisted_install | ||
online: true | ||
state: present | ||
loop: "{{ setup_acm_agents_inventory }}" | ||
loop_control: | ||
loop_var: bmc | ||
|
||
- name: Check if the desired agents appear | ||
community.kubernetes.k8s_info: | ||
api_version: agent-install.openshift.io/v1beta1 | ||
kind: Agent | ||
kubeconfig: "{{ setup_acm_agents_kubeconfig_file | default(omit) }}" | ||
namespace: "{{ setup_acm_agents_infraenv_name }}" | ||
register: _setup_acm_agents_agent_info | ||
until: | ||
- "'resources' in _setup_acm_agents_agent_info" | ||
- _setup_acm_agents_agent_info.resources | length == setup_acm_agents_inventory | length | ||
retries: 20 | ||
delay: 60 | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- name: Pre run validations | ||
ansible.builtin.include_tasks: validations.yml | ||
|
||
- name: Boot hosts with a discovery image, ready to be provisioned | ||
ansible.builtin.include_tasks: create-agent.yml | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
- name: "Assert parameters" | ||
ansible.builtin.assert: | ||
that: | ||
- setup_acm_agents_inventory is defined | ||
- setup_acm_agents_inventory | type_debug == "list" | ||
- setup_acm_agents_inventory | length > 0 | ||
- setup_acm_agents_infraenv_name is defined | ||
fail_msg: "At least one of the parameters requirements is missing" | ||
... |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: missing s after agent
setup_acm_agents_inventory