-
Notifications
You must be signed in to change notification settings - Fork 21
Use systemd socket activation for Foreman #118
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?
Conversation
|
Instead of enforcing Apache to be present and an ordering, could you use the |
I had that for a moment, but the type of the result changes to a On the other hand, perhaps we should rely more on health checks for ready detection. Then the Smart Proxy registration also feels like it doesn't belong in the Foreman role. Perhaps we need to swap the order of Foreman and Foreman Proxy. That stuff is easier in Puppet IMHO. |
Not that you say that, I am surprised it's in that role as well due to what I would have thought are order of operations. I suppose it's there as the last action with the way the playbook is organized. I think in past iterations where we played with Ansible we made registration it's own role to control it better. Ahh yes, back in the day, we had a spark of an idea. Then you have #81 which changes things and negates this being here all together I think. |
roles/foreman/tasks/main.yaml
Outdated
| ansible.builtin.uri: | ||
| url: 'http://{{ ansible_hostname }}:3000/api/v2/ping' | ||
| url: '{{ foreman_url }}/api/v2/ping' | ||
| validate_certs: false # TODO |
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.
| validate_certs: false # TODO | |
| ca_path: '{{ ca_certificate }}' |
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.
When I try this I get:
The conditional check 'foreman_status.status == 200' failed. The error was: error while evaluating conditional (foreman_status.status == 200): 'dict object' has no attribute 'status'. 'dict object' has no attribute 'status'
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.
Weird. In Line 126 you mean?
roles/foreman/tasks/main.yaml
Outdated
| url: "https://{{ ansible_fqdn }}:9090" | ||
| server_url: "http://{{ ansible_fqdn }}:3000" | ||
| server_url: "{{ foreman_url }}" | ||
| validate_certs: false # TODO |
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.
We don't support ca_path today in FAM. Should we?
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.
I was looking for it and now I'm wondering if validate_certs: '{{ ca_certificate }}' works. https://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification says verify='/path/to/certfile' is supported and looking at https://github.com/theforeman/foreman-ansible-modules/blob/2343e66adf65aac42f2d26a076d555102320bcc6/plugins/inventory/foreman.py#L266 I'd think that works. Not sure about https://github.com/theforeman/foreman-ansible-modules/blob/2343e66adf65aac42f2d26a076d555102320bcc6/plugins/module_utils/foreman_helper.py#L617 but if we go that route, it'd make sense to me to copy requests' API because it saves a parameter.
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.
It saves one, yes, but diverges from ansible.builtin.uri API, which is the one Ansible users are more familiar with.
The problem (today) is https://github.com/theforeman/foreman-ansible-modules/blob/2343e66adf65aac42f2d26a076d555102320bcc6/plugins/module_utils/foreman_helper.py#L373 which makes it a boolean, not a string.
| [Unit] | ||
| Requires=foreman.socket |
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.
This is the only thing needed for it to do socket activation? 🤯
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.
Mhh, but the tests are failing with error 500, so maybe it isn't?
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.
Does the socket "just" need to be started too?
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.
This is the only thing needed for it to do socket activation? 🤯
Pretty much yes. It ends up setting the right env vars and Puma picks that up because we tell it to (https://github.com/theforeman/foreman/blob/75dc40095546966477a927911e715263c42d1bea/config/puma/production.rb#L35-L38).
Mhh, but the tests are failing with error 500, so maybe it isn't?
I think that's because of async. Looking at the Pulp failures I get the impression the service is started before migrations ran. That's why I'll split this off into 2 PRs.
Does the socket "just" need to be started too?
Starting foreman.service (as we do) will activate the socket so it shouldn't be needed to enable it, but we could. In theory we could only start the socket and let foreman.service start on demand but I'm not sure we want to go that route.
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.
Sorry, async was a different patch. Apache fails with:
[Thu Mar 13 18:02:39.887738 2025] [proxy:warn] [pid 707:tid 891] [client 192.168.122.14:52218] AH01144: No protocol handler was valid for the URL / (scheme 'unix'). If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
Turns out the template had a trailing slash and then it couldn't find the right socket anymore.
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.
Starting
foreman.service(as we do) will activate the socket so it shouldn't be needed to enable it, but we could. In theory we could only start the socket and letforeman.servicestart on demand but I'm not sure we want to go that route.
There is a good reason to start from Ansible: we should restart it if a change is made.
It does not, because |
|
Next issue: We handled this in our foreman-selinux package but that's no longer installed on the host. |
3c95a0d to
19a28df
Compare
Nothing prevents us from installing it again. Or we extend/adjust audit2allow says |
19a28df to
995fb64
Compare
If you use |
|
@ekohl Would you mind rebasing when you get a moment? |
This makes it easier to change where the service listens on.
This means certificates are properly verified, both server side and client side.
| foreman_oauth_consumer_secret: abcdefghijklmnopqrstuvwxyz123456 | ||
| foreman_listen_stream: /run/httpd.foreman.sock | ||
| foreman_url: "https://{{ ansible_fqdn }}" | ||
| httpd_foreman_backend: "unix://{{ foreman_listen_stream }}|http://%{HTTP_HOST}/" |
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.
I'm surprised all three of these are not the role defaults.
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.
Because they're connected: my thought was that the roles should be dependent and only on the playbook level you can relate them.
| --- | ||
| foreman_container_image: "quay.io/evgeni/foreman-rpm" | ||
| foreman_container_tag: "nightly" | ||
| foreman_listen_stream: localhost:3000 |
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.
I think what I don't know enough about is why we wouldn't default this to /run/httpd.foreman.sock if our intent is to use systemd sock activation.
@ehelms as you requested, an example of using systemd socket activation an unix sockets.
It changes the connections to go through Apache, which may or may not be right.