go-ansible
go-ansible copied to clipboard
How to properly provide multiple ssh extra args
I'm hitting an issue where I'm getting an error trying to use more than one ssh extra arg:
This is the command that the library ends up running. This works when I run it manually.
/opt/homebrew/bin/ansible-playbook --extra-vars {"ansible_sudo_pass":"REDACTED"} --forks 5 --inventory 192.168.1.2, --ssh-extra-args ' -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/dev/null' --timeout 300 --user myuser --become-method sudo --become-user root /var/folders/3z/4hf8d_g93h77jtsj82y3ysb80000gn/T/.ansible-3124354280
When I run this via my go code and this library:
"tasks": [
{
"hosts": {
"192.168.1.2": {
"action": "gather_facts",
"changed": false,
"msg": "Failed to connect to the host via ssh: command-line line 0: keyword stricthostkeychecking extra arguments at end of line",
"unreachable": true
}
},
"task": {
"duration": {
"end": "2024-02-29T16:37:06.509821Z",
"start": "2024-02-29T16:37:06.492520Z"
},
"id": "66d3b971-6cc6-a701-202c-000000000009",
"name": "Gathering Facts",
"path": "/var/folders/3z/4hf8d_g93h77jtsj82y3ysb80000gn/T/.ansible-3124354280:1"
}
}
]
options.AnsibleConnectionOptions.SSHExtraArgs is just a string so how should multiple arguments be specified?
My connection options is being constructed like so:
"Connection": {
"AskPass": false,
"Connection": "",
"PrivateKey": "",
"SCPExtraArgs": "",
"SFTPExtraArgs": "",
"SSHCommonArgs": "",
"SSHExtraArgs": " -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/dev/null",
"Timeout": 300,
"User": "myuser"
},