Skip to content

Commit b4d2269

Browse files
BenoitKnechtphilpep
authored andcommitted
ansible: Support SSH args from environment
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 <[email protected]>
1 parent 14c35b1 commit b4d2269

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

testinfra/utils/ansible_runner.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ def get_ansible_host(config, inventory, host, ssh_config=None, ssh_identity_file
101101
},
102102
"environment": "ANSIBLE_REMOTE_PORT",
103103
},
104+
"ansible_ssh_common_args": {
105+
"ini": {
106+
"section": "ssh_connection",
107+
"key": "ssh_common_args",
108+
},
109+
"environment": "ANSIBLE_SSH_COMMON_ARGS",
110+
},
111+
"ansible_ssh_extra_args": {
112+
"ini": {
113+
"section": "ssh_connection",
114+
"key": "ssh_extra_args",
115+
},
116+
"environment": "ANSIBLE_SSH_EXTRA_ARGS",
117+
},
104118
"ansible_user": {
105119
"ini": {
106120
"section": "defaults",
@@ -149,8 +163,8 @@ def get_config(name, default=None):
149163
kwargs["ssh_extra_args"] = " ".join(
150164
[
151165
config.get("ssh_connection", "ssh_args", fallback=""),
152-
hostvars.get("ansible_ssh_common_args", ""),
153-
hostvars.get("ansible_ssh_extra_args", ""),
166+
get_config("ansible_ssh_common_args", ""),
167+
get_config("ansible_ssh_extra_args", ""),
154168
]
155169
).strip()
156170

0 commit comments

Comments
 (0)