Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ group1: # host_group
ansible_host: 127.0.0.2
ansible_user: manager
ansible_password:
ansible_port: 19020
_meta:
_skip: true

Expand All @@ -22,6 +23,7 @@ group2:
ansible_host: 172.19.0.1
ansible_user: postgres
ansible_password:
ansible_port: 19222

host4:
ansible_host: 172.99.99.99
Expand Down
3 changes: 3 additions & 0 deletions sshgen/generators/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def convert(parsed_hosts: CommentedMap) -> list[HostModel]:
ansible_user=host_details['ansible_user'],
)

if host_details.get('ansible_port'):
model.ansible_port = host_details['ansible_port']

meta = host_details.get('_meta', {})
auth_type = meta.get('_auth_type')
auth_path = meta.get('_auth_path')
Expand Down
3 changes: 2 additions & 1 deletion sshgen/generators/sshconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def _process(self, model: HostModel) -> str:
temp = self.ssh_template.replace('{{ host }}', model.host) \
.replace('{{ hostname }}', model.ansible_host) \
.replace('{{ host_comment }}', model.host_group) \
.replace('{{ ssh_user }}', model.ansible_user)
.replace('{{ ssh_user }}', model.ansible_user) \
.replace('{{ port }}', f'Port {str(model.ansible_port)}')

if model.meta_fields:
if model.meta_fields.aliases:
Expand Down
1 change: 1 addition & 0 deletions sshgen/models/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ class HostModel:
host_group: str
ansible_host: str
ansible_user: str
ansible_port: int = 22
meta_fields: MetaFieldsModel | None = None
1 change: 1 addition & 0 deletions sshgen/templates/ssh_config.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Host {{ host }} {{ host_alias }} # {{ host_comment }}
HostName {{ hostname }}
User {{ ssh_user }}
{{ port }}
{{ identification }}