Skip to content

Commit

Permalink
ansible: Support SSH args from environment
Browse files Browse the repository at this point in the history
As an extension of #627, this commit adds the ability to get
`ansible_ssh_common_args` and `ansible_ssh_extra_args` from the configuration
file or environment variables, with the expected precedence:

| Configuration File                      | Host Variable             | Environment               |
| --------------------------------------- | ------------------------- | ------------------------- |
| `[ssh_connection]`<br>`ssh_common_args` | `ansible_ssh_common_args` | `ANSIBLE_SSH_COMMON_ARGS` |
| `[ssh_connection]`<br>`ssh_extra_args`  | `ansible_ssh_extra_args`  | `ANSIBLE_SSH_EXTRA_ARGS`  |

Signed-off-by: Benoît Knecht <bknecht@protonmail.ch>
  • Loading branch information
BenoitKnecht authored and philpep committed Jan 20, 2022
1 parent 14c35b1 commit b4d2269
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions testinfra/utils/ansible_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ def get_ansible_host(config, inventory, host, ssh_config=None, ssh_identity_file
},
"environment": "ANSIBLE_REMOTE_PORT",
},
"ansible_ssh_common_args": {
"ini": {
"section": "ssh_connection",
"key": "ssh_common_args",
},
"environment": "ANSIBLE_SSH_COMMON_ARGS",
},
"ansible_ssh_extra_args": {
"ini": {
"section": "ssh_connection",
"key": "ssh_extra_args",
},
"environment": "ANSIBLE_SSH_EXTRA_ARGS",
},
"ansible_user": {
"ini": {
"section": "defaults",
Expand Down Expand Up @@ -149,8 +163,8 @@ def get_config(name, default=None):
kwargs["ssh_extra_args"] = " ".join(
[
config.get("ssh_connection", "ssh_args", fallback=""),
hostvars.get("ansible_ssh_common_args", ""),
hostvars.get("ansible_ssh_extra_args", ""),
get_config("ansible_ssh_common_args", ""),
get_config("ansible_ssh_extra_args", ""),
]
).strip()

Expand Down

0 comments on commit b4d2269

Please sign in to comment.