Skip to content

Commit c9f77db

Browse files
authored
Merge pull request #44 from linux-kdevops/alt-ssh-port
Enable users to set an alternate ssh port for Ansible
2 parents da754be + c1f1486 commit c9f77db

23 files changed

Lines changed: 289 additions & 94 deletions

File tree

kconfigs/Kconfig.ansible_cfg

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,47 @@ config ANSIBLE_CFG_INVENTORY
316316

317317
endif # ANSIBLE_CFG_INVENTORY_CUSTOM
318318

319+
config ANSIBLE_CFG_SSH_PORT_SET_BY_CLI
320+
bool
321+
default $(shell, scripts/check-cli-set-var.sh ANSIBLE_CFG_SSH_PORT)
322+
323+
config ANSIBLE_CFG_SSH_PORT_CUSTOM
324+
bool "Enable a custom Ansible SSH port setting"
325+
default n
326+
help
327+
When this setting is enabled, specify the SSH port for
328+
Ansible to use when connecting to target nodes.
329+
330+
When this setting is disabled, kdevops uses the default
331+
SSH port (22), which can be overridden with
332+
"ANSIBLE_CFG_SSH_PORT=NN" on the "make" command line.
333+
334+
This is useful when your target hosts use a non-standard
335+
SSH port for security or network configuration reasons.
336+
337+
if ANSIBLE_CFG_SSH_PORT_CUSTOM
338+
339+
config ANSIBLE_CFG_SSH_PORT
340+
int "Ansible SSH port"
341+
output yaml
342+
help
343+
Set the SSH port for Ansible to use when connecting to target
344+
nodes. The default port is 22.
345+
346+
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh_connection.html#parameter-remote_port
347+
348+
endif # ANSIBLE_CFG_SSH_PORT_CUSTOM
349+
350+
if !ANSIBLE_CFG_SSH_PORT_CUSTOM
351+
352+
config ANSIBLE_CFG_SSH_PORT
353+
int
354+
output yaml
355+
default 22 if !ANSIBLE_CFG_SSH_PORT_SET_BY_CLI
356+
default $(shell, ./scripts/append-makefile-vars-int.sh $(ANSIBLE_CFG_SSH_PORT)) if ANSIBLE_CFG_SSH_PORT_SET_BY_CLI
357+
358+
endif # !ANSIBLE_CFG_SSH_PORT_CUSTOM
359+
319360
if DISTRO_OPENSUSE
320361

321362
config ANSIBLE_CFG_RECONNECTION_RETRIES

playbooks/nixos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@
430430
python3 {{ playbook_dir }}/../scripts/update_ssh_config_nixos.py update \
431431
{{ item }} \
432432
{{ nixos_vm_ips[item] }} \
433-
22 \
433+
{{ ansible_cfg_ssh_port }} \
434434
kdevops \
435435
{{ nixos_ssh_config_file | default(ansible_env.HOME + '/.ssh/config') }} \
436436
{{ ssh_key_path_for_config.stdout | trim }} \

playbooks/roles/ansible_cfg/templates/ansible.cfg.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ playbook_on_stats_msg_color = bright green
4747
[callback_profile_tasks]
4848
summary_only = true
4949
{% endif %}
50+
[ssh_connection]
51+
remote_port = {{ ansible_cfg_ssh_port }}
5052
{% if ansible_facts['distribution'] == 'openSUSE' %}
53+
5154
[connection]
5255
retries = {{ ansible_cfg_reconnection_retries }}
5356
{% endif %}

playbooks/roles/base_image/templates/virt-builder.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mkdir {{ target_dir }}
1212
copy-in {{ guestfs_distro_source_and_dest_file }}:{{ target_dir }}
1313
{% endif %}
1414

15-
install sudo,qemu-guest-agent,python3,bash
15+
install sudo,qemu-guest-agent,python3,bash,policycoreutils-python-utils
1616

1717
# get rid of any rescue initramfs images, and prevent new ones from being generated
1818
uninstall dracut-config-rescue

playbooks/roles/gen_tfvars/templates/aws/terraform.tfvars.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ aws_ebs_volume_throughput = {{ terraform_aws_ebs_volume_throughput }}
1818
ssh_config_pubkey_file = "{{ kdevops_terraform_ssh_config_pubkey_file }}"
1919
ssh_config_user = "{{ kdevops_terraform_ssh_config_user }}"
2020
ssh_config = "{{ sshconfig }}"
21+
ssh_config_port = {{ ansible_cfg_ssh_port }}
2122

2223
ssh_config_update = "{{ kdevops_terraform_ssh_config_update | lower }}"
2324
ssh_config_use_strict_settings = "{{ kdevops_terraform_ssh_config_update_strict | lower }}"

playbooks/roles/gen_tfvars/templates/azure/terraform.tfvars.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ azure_managed_disks_tier = "{{ terraform_azure_managed_disks_tier }}"
1313
ssh_config_pubkey_file = "{{ kdevops_terraform_ssh_config_pubkey_file }}"
1414
ssh_config_user = "{{ kdevops_terraform_ssh_config_user }}"
1515
ssh_config = "{{ sshconfig }}"
16+
ssh_config_port = {{ ansible_cfg_ssh_port }}
1617

1718
ssh_config_update = "{{ kdevops_terraform_ssh_config_update | lower }}"
1819
ssh_config_use_strict_settings = "{{ kdevops_terraform_ssh_config_update_strict | lower }}"

playbooks/roles/gen_tfvars/templates/gce/terraform.tfvars.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ gce_disk_throughput = {{ terraform_gce_disk_throughput }}
2020
ssh_config_pubkey_file = "{{ kdevops_terraform_ssh_config_pubkey_file }}"
2121
ssh_config_user = "{{ kdevops_terraform_ssh_config_user }}"
2222
ssh_config = "{{ sshconfig }}"
23+
ssh_config_port = {{ ansible_cfg_ssh_port }}
2324

2425
ssh_config_update = "{{ kdevops_terraform_ssh_config_update | lower }}"
2526
ssh_config_use_strict_settings = "{{ kdevops_terraform_ssh_config_update_strict | lower }}"

playbooks/roles/gen_tfvars/templates/lambdalabs/terraform.tfvars.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ssh_config_pubkey_file = "{{ kdevops_terraform_ssh_config_pubkey_file }}"
77
ssh_config_privkey_file = "{{ kdevops_terraform_ssh_config_privkey_file }}"
88
ssh_config_user = "{{ kdevops_terraform_ssh_config_user }}"
99
ssh_config = "{{ sshconfig }}"
10+
ssh_config_port = {{ ansible_cfg_ssh_port }}
1011
# Use unique SSH config file per directory to avoid conflicts
1112
ssh_config_name = "{{ kdevops_ssh_config_prefix }}{{ topdir_path_sha256sum[:8] }}"
1213

playbooks/roles/gen_tfvars/templates/oci/terraform.tfvars.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ oci_sparse_volume_device_file_name = "{{ terraform_oci_sparse_volume_device_file
2525
ssh_config_pubkey_file = "{{ kdevops_terraform_ssh_config_pubkey_file }}"
2626
ssh_config_user = "{{ kdevops_terraform_ssh_config_user }}"
2727
ssh_config = "{{ sshconfig }}"
28+
ssh_config_port = {{ ansible_cfg_ssh_port }}
2829

2930
ssh_config_update = "{{ kdevops_terraform_ssh_config_update | lower }}"
3031
ssh_config_use_strict_settings = "{{ kdevops_terraform_ssh_config_update_strict | lower }}"

playbooks/roles/gen_tfvars/templates/openstack/terraform.tfvars.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ssh_pubkey_name = "{{ terraform_openstack_ssh_pubkey_name }}"
77
ssh_config_pubkey_file = "{{ kdevops_terraform_ssh_config_pubkey_file }}"
88
ssh_config_user = "{{ kdevops_terraform_ssh_config_user }}"
99
ssh_config = "{{ sshconfig }}"
10+
ssh_config_port = {{ ansible_cfg_ssh_port }}
1011

1112
ssh_config_update = "{{ kdevops_terraform_ssh_config_update | lower }}"
1213
ssh_config_use_strict_settings = "{{ kdevops_terraform_ssh_config_update_strict | lower }}"

0 commit comments

Comments
 (0)