Skip to content

Instantly share code, notes, and snippets.

@hostmaster
Last active March 18, 2022 03:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hostmaster/073e2ad2b78617a2ef63 to your computer and use it in GitHub Desktop.
Save hostmaster/073e2ad2b78617a2ef63 to your computer and use it in GitHub Desktop.
# dict key tranformation table
_ssh_to_ansible = {
'user': 'ansible_ssh_user',
'hostname': 'ansible_ssh_host',
'identityfile': 'ansible_ssh_private_key_file',
'port': 'ansible_ssh_port'
}
# host_config = config.lookup(box_name) # dict
temp = {}
for k in _ssh_to_ansible:
temp[_ssh_to_ansible[k]] = host_config[k]
@jtsoi
Copy link

jtsoi commented Jul 20, 2015

@hostmaster that looks pretty minimal to me.

You could:

for host_key, ansible_key  in _ssh_to_ansible.items():
  temp[ansible_key] = host_config[host_key]

Other than that, no ideas.

@hostmaster
Copy link
Author

@jtsoi Thanks.

Copy link

ghost commented Jul 21, 2015

Missing the context. Both of your solutions does the job. If you're after minimal code, there's also dict comprehension:

temp = {k: host_config[k] for k, v in _ssh_to_ansible.items()}

@hostmaster
Copy link
Author

@vs-ab thank it is exactly what i am looking for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment