-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Hop nodes for k8s #13904
Hop nodes for k8s #13904
Changes from 43 commits
21aca69
e45fe24
6e21bde
9361ccd
2835039
7cb6bf0
4df8fe5
26f1e63
80f0ed2
7202bca
12740b2
748de47
e578ce0
311f0ef
0177c37
218e93a
e8c8f1c
315aa6c
0996e94
569a674
cb10ce2
e203313
fe15670
cf4dba0
6bd86ee
753baff
b30c2bd
856b12d
694bb99
558c135
2eecef4
34f12ce
0e8fab8
52ed376
b1125f1
99a3348
24c1f2c
92620d1
bd759fe
bc538c2
cb0f4bb
8a4678c
d9d6f82
123f590
7501542
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 |
---|---|---|
@@ -1,20 +1,16 @@ | ||
{% verbatim %} | ||
--- | ||
- hosts: all | ||
become: yes | ||
tasks: | ||
- name: Create the receptor user | ||
user: | ||
{% verbatim %} | ||
name: "{{ receptor_user }}" | ||
{% endverbatim %} | ||
shell: /bin/bash | ||
- name: Enable Copr repo for Receptor | ||
command: dnf copr enable ansible-awx/receptor -y | ||
{% if instance.node_type == "execution" %} | ||
- import_role: | ||
name: ansible.receptor.podman | ||
{% endif %} | ||
- import_role: | ||
name: ansible.receptor.setup | ||
- name: Install ansible-runner | ||
pip: | ||
name: ansible-runner | ||
executable: pip3.9 | ||
{% endverbatim %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
--- | ||
collections: | ||
- name: ansible.receptor | ||
version: 1.1.0 | ||
- name: https://github.com/ansible/receptor-collection.git | ||
type: git | ||
version: main | ||
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. do we need to point this to 2.0.0 version? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import ipaddress | ||
import os | ||
import tarfile | ||
import time | ||
import re | ||
|
||
import asn1 | ||
from awx.api import serializers | ||
|
@@ -40,6 +42,8 @@ | |
# │ │ └── receptor.key | ||
# │ └── work-public-key.pem | ||
# └── requirements.yml | ||
|
||
|
||
class InstanceInstallBundle(GenericAPIView): | ||
name = _('Install Bundle') | ||
model = models.Instance | ||
|
@@ -49,9 +53,9 @@ class InstanceInstallBundle(GenericAPIView): | |
def get(self, request, *args, **kwargs): | ||
instance_obj = self.get_object() | ||
|
||
if instance_obj.node_type not in ('execution',): | ||
if instance_obj.node_type not in ('execution', 'hop'): | ||
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. it would be good to make use of the enum objects instead of bare strings, like we do elsewhere 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.
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. Yeah, I think this is still an open item but only a minor code style thing. |
||
return Response( | ||
data=dict(msg=_('Install bundle can only be generated for execution nodes.')), | ||
data=dict(msg=_('Install bundle can only be generated for execution or hop nodes.')), | ||
status=status.HTTP_400_BAD_REQUEST, | ||
) | ||
|
||
|
@@ -66,37 +70,37 @@ def get(self, request, *args, **kwargs): | |
# generate and write the receptor key to receptor/tls/receptor.key in the tar file | ||
key, cert = generate_receptor_tls(instance_obj) | ||
|
||
def tar_addfile(tarinfo, filecontent): | ||
tarinfo.mtime = time.time() | ||
tarinfo.size = len(filecontent) | ||
tar.addfile(tarinfo, io.BytesIO(filecontent)) | ||
|
||
key_tarinfo = tarfile.TarInfo(f"{instance_obj.hostname}_install_bundle/receptor/tls/receptor.key") | ||
key_tarinfo.size = len(key) | ||
tar.addfile(key_tarinfo, io.BytesIO(key)) | ||
tar_addfile(key_tarinfo, key) | ||
|
||
cert_tarinfo = tarfile.TarInfo(f"{instance_obj.hostname}_install_bundle/receptor/tls/receptor.crt") | ||
cert_tarinfo.size = len(cert) | ||
tar.addfile(cert_tarinfo, io.BytesIO(cert)) | ||
tar_addfile(cert_tarinfo, cert) | ||
|
||
# generate and write install_receptor.yml to the tar file | ||
playbook = generate_playbook().encode('utf-8') | ||
playbook = generate_playbook(instance_obj).encode('utf-8') | ||
playbook_tarinfo = tarfile.TarInfo(f"{instance_obj.hostname}_install_bundle/install_receptor.yml") | ||
playbook_tarinfo.size = len(playbook) | ||
tar.addfile(playbook_tarinfo, io.BytesIO(playbook)) | ||
tar_addfile(playbook_tarinfo, playbook) | ||
|
||
# generate and write inventory.yml to the tar file | ||
inventory_yml = generate_inventory_yml(instance_obj).encode('utf-8') | ||
inventory_yml_tarinfo = tarfile.TarInfo(f"{instance_obj.hostname}_install_bundle/inventory.yml") | ||
inventory_yml_tarinfo.size = len(inventory_yml) | ||
tar.addfile(inventory_yml_tarinfo, io.BytesIO(inventory_yml)) | ||
tar_addfile(inventory_yml_tarinfo, inventory_yml) | ||
|
||
# generate and write group_vars/all.yml to the tar file | ||
group_vars = generate_group_vars_all_yml(instance_obj).encode('utf-8') | ||
group_vars_tarinfo = tarfile.TarInfo(f"{instance_obj.hostname}_install_bundle/group_vars/all.yml") | ||
group_vars_tarinfo.size = len(group_vars) | ||
tar.addfile(group_vars_tarinfo, io.BytesIO(group_vars)) | ||
tar_addfile(group_vars_tarinfo, group_vars) | ||
|
||
# generate and write requirements.yml to the tar file | ||
requirements_yml = generate_requirements_yml().encode('utf-8') | ||
requirements_yml_tarinfo = tarfile.TarInfo(f"{instance_obj.hostname}_install_bundle/requirements.yml") | ||
requirements_yml_tarinfo.size = len(requirements_yml) | ||
tar.addfile(requirements_yml_tarinfo, io.BytesIO(requirements_yml)) | ||
tar_addfile(requirements_yml_tarinfo, requirements_yml) | ||
|
||
# respond with the tarfile | ||
f.seek(0) | ||
|
@@ -105,8 +109,10 @@ def get(self, request, *args, **kwargs): | |
return response | ||
|
||
|
||
def generate_playbook(): | ||
return render_to_string("instance_install_bundle/install_receptor.yml") | ||
def generate_playbook(instance_obj): | ||
playbook_yaml = render_to_string("instance_install_bundle/install_receptor.yml", context=dict(instance=instance_obj)) | ||
# convert consecutive newlines with a single newline | ||
return re.sub(r'\n+', '\n', playbook_yaml) | ||
|
||
|
||
def generate_requirements_yml(): | ||
|
@@ -118,7 +124,12 @@ def generate_inventory_yml(instance_obj): | |
|
||
|
||
def generate_group_vars_all_yml(instance_obj): | ||
return render_to_string("instance_install_bundle/group_vars/all.yml", context=dict(instance=instance_obj)) | ||
peers = [] | ||
for instance in instance_obj.peers.all(): | ||
peers.append(dict(host=instance.hostname, port=instance.listener_port)) | ||
all_yaml = render_to_string("instance_install_bundle/group_vars/all.yml", context=dict(instance=instance_obj, peers=peers)) | ||
# convert consecutive newlines with a single newline | ||
return re.sub(r'\n+', '\n', all_yaml) | ||
|
||
|
||
def generate_receptor_tls(instance_obj): | ||
|
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.
Shouldn't this be removed from previous installed receptors?
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, can you clarify the question? The next receptor-collection version will install receptor via these releases by default https://github.com/ansible/receptor/releases
thus the Copr repo is no longer needed going forward
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 thinking of upgrades of previous installs.