-
Notifications
You must be signed in to change notification settings - Fork 37
Add cloud-connector as a native foremanctl feature #569
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
base: master
Are you sure you want to change the base?
Changes from 12 commits
072ebd9
1e4b2be
cdd201b
d309d1c
14c71c8
9417448
3abcf7f
31329c2
8ed3952
fafe461
84335ce
eedc053
7160f79
0e581b7
68c0ef3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| --- | ||
| - name: Verify cloud-connector is not used with iop | ||
| ansible.builtin.assert: | ||
| that: | ||
| - "'iop' not in enabled_features" | ||
| fail_msg: >- | ||
| The cloud-connector feature cannot be used together with the iop feature. | ||
| Remove one of them with --remove-feature before deploying. | ||
|
|
||
| - name: Check that consumer certificate exists | ||
| ansible.builtin.stat: | ||
| path: /etc/pki/consumer/cert.pem | ||
| register: check_cloud_connector_consumer_cert | ||
|
|
||
| - name: Verify consumer certificate exists | ||
| ansible.builtin.assert: | ||
| that: | ||
| - check_cloud_connector_consumer_cert.stat.exists | ||
| fail_msg: >- | ||
| /etc/pki/consumer/cert.pem not found. | ||
| The system must be registered with subscription-manager. | ||
|
|
||
| - name: Check that yggdrasil-worker-forwarder package is available | ||
| ansible.builtin.command: dnf info yggdrasil-worker-forwarder | ||
| changed_when: false | ||
| failed_when: false | ||
| register: check_cloud_connector_pkg_check | ||
|
|
||
| - name: Verify yggdrasil-worker-forwarder is available | ||
| ansible.builtin.assert: | ||
| that: | ||
| - check_cloud_connector_pkg_check.rc == 0 | ||
| fail_msg: >- | ||
| The yggdrasil-worker-forwarder package is not available. | ||
| Ensure the appropriate repository is enabled. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| cloud_connector_url: "https://{{ ansible_facts['fqdn'] }}" | ||
| cloud_connector_admin_user: admin | ||
| cloud_connector_admin_password: changeme # noqa: no-static-secrets | ||
| cloud_connector_service_user: cloud_connector_admin_user | ||
| cloud_connector_service_password: changeme # noqa: no-static-secrets | ||
| cloud_connector_config_file: /etc/rhc/workers/foreman_rh_cloud.toml | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| - name: Update system CA trust | ||
| ansible.builtin.command: update-ca-trust | ||
| changed_when: true # noqa: no-changed-when | ||
| listen: Foreman CA changed | ||
|
|
||
| - name: Restart rhcd | ||
| ansible.builtin.systemd_service: | ||
| name: rhcd | ||
| state: restarted | ||
| daemon_reload: true | ||
|
jeremylenz marked this conversation as resolved.
|
||
| listen: Foreman CA changed | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| - name: Create systemd drop-in directory for rhcd | ||
| ansible.builtin.file: | ||
| state: directory | ||
| path: /etc/systemd/system/rhcd.service.d | ||
| owner: root | ||
| group: root | ||
| mode: '0755' | ||
|
|
||
| - name: Deploy HTTP proxy systemd drop-in for rhcd | ||
| ansible.builtin.template: | ||
| src: proxy.conf.j2 | ||
| dest: /etc/systemd/system/rhcd.service.d/proxy.conf | ||
| owner: root | ||
| group: root | ||
| mode: '0644' | ||
| notify: Restart rhcd |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| --- | ||
| - name: Install rhc and yggdrasil-worker-forwarder | ||
| ansible.builtin.package: | ||
| name: | ||
| - rhc | ||
|
jeremylenz marked this conversation as resolved.
|
||
| - yggdrasil-worker-forwarder | ||
| disable_plugin: foreman-protector | ||
|
|
||
| - name: Create cloud connector role | ||
| theforeman.foreman.role: | ||
| name: Cloud Connector | ||
| filters: | ||
| - permissions: | ||
| - dispatch_cloud_requests | ||
| server_url: "{{ cloud_connector_url }}" | ||
| username: "{{ cloud_connector_admin_user }}" | ||
| password: "{{ cloud_connector_admin_password }}" | ||
| ca_path: "{{ foreman_ca_certificate }}" | ||
| state: present | ||
|
|
||
| - name: Create cloud connector service user | ||
| theforeman.foreman.user: | ||
| login: "{{ cloud_connector_service_user }}" | ||
| user_password: "{{ cloud_connector_service_password }}" | ||
| mail: "{{ cloud_connector_service_user }}@localhost" | ||
| auth_source: Internal | ||
| roles: | ||
| - Cloud Connector | ||
| admin: false | ||
| server_url: "{{ cloud_connector_url }}" | ||
| username: "{{ cloud_connector_admin_user }}" | ||
| password: "{{ cloud_connector_admin_password }}" | ||
| ca_path: "{{ foreman_ca_certificate }}" | ||
| state: present | ||
|
|
||
| - name: Configure foreman-rh-cloud worker | ||
| ansible.builtin.template: | ||
| src: foreman_rh_cloud.toml.j2 | ||
| dest: "{{ cloud_connector_config_file }}" | ||
| owner: root | ||
| group: root | ||
| mode: '0640' | ||
| notify: Restart rhcd | ||
|
|
||
| - name: Create rhcd worker script | ||
| ansible.builtin.copy: | ||
| dest: /usr/libexec/rhc/foreman-rh-cloud-worker | ||
| content: | | ||
| #!/bin/bash | ||
|
|
||
| CONFIG_FILE="{{ cloud_connector_config_file }}" exec /usr/libexec/yggdrasil-worker-forwarder | ||
| owner: root | ||
| group: root | ||
| mode: '0755' | ||
|
|
||
| - name: Add Foreman CA to system trust store | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this how we do it today? This is an anti-pattern we have been trying to avoid.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We need it here because
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was apprehensive about this too. I figured we can change it later..
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
These are both 404s because they were moved quite a bit ago. I think we need to consider udpating yggdrasil-worker-forwarder vs. starting this trend of relying on the system store. Let's phone a friend for another opinion. @evgeni ☎️
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to update it anyway to use DBUS (so it can run on RHEL 10), so we can probably just tack that change on there.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/theforeman/yggdrasil-worker-forwarder doesn't seem to use Github Issues, so I will create an internal Jira for that.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the description of https://redhat.atlassian.net/browse/SAT-27307. However, ideally I would like this PR to be merged and use the "incorrect" approach temporarily, to move things forward,. |
||
| ansible.builtin.copy: | ||
| src: "{{ foreman_ca_certificate }}" | ||
| dest: /etc/pki/ca-trust/source/anchors/foreman-ca.pem | ||
| remote_src: true | ||
| owner: root | ||
| group: root | ||
| mode: '0644' | ||
| notify: Foreman CA changed | ||
|
|
||
| - name: Ensure rhcd started and enabled | ||
| ansible.builtin.service: | ||
| name: rhcd | ||
| state: started | ||
| enabled: true | ||
|
|
||
| - name: Read client ID from CN of consumer certificate | ||
| ansible.builtin.command: openssl x509 -in /etc/pki/consumer/cert.pem -subject -noout | ||
| register: cloud_connector_cert_output | ||
| changed_when: false | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above but opposite. Idempotency?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is correct — |
||
|
|
||
| - name: Set rhc_instance_id in Foreman | ||
|
jeremylenz marked this conversation as resolved.
|
||
| theforeman.foreman.setting: | ||
| name: rhc_instance_id | ||
| value: "{{ cloud_connector_client_id }}" | ||
| server_url: "{{ cloud_connector_url }}" | ||
| username: "{{ cloud_connector_admin_user }}" | ||
| password: "{{ cloud_connector_admin_password }}" | ||
| ca_path: "{{ foreman_ca_certificate }}" | ||
| vars: | ||
| cloud_connector_client_id: "{{ cloud_connector_cert_output.stdout | regex_search('CN\\s?=\\s?([a-z0-9-]+)', '\\1') | first }}" | ||
|
|
||
| - name: Enable automatic inventory upload | ||
| theforeman.foreman.setting: | ||
| name: allow_auto_inventory_upload | ||
| value: true | ||
| server_url: "{{ cloud_connector_url }}" | ||
| username: "{{ cloud_connector_admin_user }}" | ||
| password: "{{ cloud_connector_admin_password }}" | ||
| ca_path: "{{ foreman_ca_certificate }}" | ||
|
|
||
| - name: Announce to Sources | ||
| ansible.builtin.uri: | ||
| url: "{{ cloud_connector_url }}/api/v2/rh_cloud/announce_to_sources" | ||
| user: "{{ cloud_connector_admin_user }}" | ||
| password: "{{ cloud_connector_admin_password }}" | ||
| method: POST | ||
| ca_path: "{{ foreman_ca_certificate }}" | ||
| force_basic_auth: true | ||
| body_format: json | ||
| status_code: [200, 201] | ||
|
|
||
| - name: Configure HTTP proxy for rhcd | ||
| ansible.builtin.include_tasks: http_proxy.yaml | ||
| when: cloud_connector_http_proxy is defined | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| exec = "/usr/libexec/yggdrasil-worker-forwarder" | ||
| protocol = "grpc" | ||
| env = [ | ||
| "FORWARDER_USER={{ cloud_connector_service_user }}", | ||
| "FORWARDER_PASSWORD={{ cloud_connector_service_password }}", | ||
| "FORWARDER_URL={{ cloud_connector_url }}/api/v2/rh_cloud/cloud_request", | ||
| "FORWARDER_HANDLER=foreman_rh_cloud" | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [Service] | ||
| Environment=HTTPS_PROXY={{ cloud_connector_http_proxy }} | ||
| Environment=NO_PROXY={{ cloud_connector_url | ansible.builtin.urlsplit('hostname') }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import pytest | ||
|
|
||
| pytestmark = pytest.mark.feature("cloud-connector") | ||
|
|
||
|
|
||
| def test_rhc_package_installed(server): | ||
| assert server.package("rhc").is_installed | ||
|
|
||
|
|
||
| def test_yggdrasil_worker_forwarder_package_installed(server): | ||
| assert server.package("yggdrasil-worker-forwarder").is_installed | ||
|
|
||
|
|
||
| def test_workers_directory_exists(server): | ||
| workers_dir = server.file("/etc/rhc/workers") | ||
| assert workers_dir.is_directory | ||
| assert workers_dir.mode == 0o755 | ||
|
|
||
|
|
||
| def test_worker_config_exists(server): | ||
| config = server.file("/etc/rhc/workers/foreman_rh_cloud.toml") | ||
| assert config.is_file | ||
| assert config.mode == 0o640 | ||
| assert config.contains("FORWARDER_HANDLER=foreman_rh_cloud") | ||
| assert config.contains("/api/v2/rh_cloud/cloud_request") | ||
|
|
||
|
|
||
| def test_worker_script_exists(server): | ||
| script = server.file("/usr/libexec/rhc/foreman-rh-cloud-worker") | ||
| assert script.is_file | ||
| assert script.mode == 0o755 | ||
| assert script.contains("yggdrasil-worker-forwarder") | ||
|
|
||
|
|
||
| def test_rhcd_service_running(server): | ||
| rhcd = server.service("rhcd") | ||
| assert rhcd.is_running | ||
| assert rhcd.is_enabled |
Uh oh!
There was an error while loading. Please reload this page.