go-ansible icon indicating copy to clipboard operation
go-ansible copied to clipboard

missing single quote character of --extra-vars

Open nguyenphituan opened this issue 2 years ago • 0 comments

Hi Apenella,

The string generated by AnsibleAdhocOptions misses single quote character around JSON string while using adhoc. Ansible 6.x refuses to read it as correct form of command:

ansibleAdhocOptions := &adhoc.AnsibleAdhocOptions{ Inventory: HostIP + "," ModuleName: "arista.eos.eos_config", Args: ""backup=yes backup_options={'dir_path':'\backup'} "", ExtraVars: map[string]interface{}{"ansible_connection": "ansible.netcommon.network_cli", "ansible_network_os": "eos", "ansible_become": "yes", "ansible_become_method": "enable"},}

Output err:

Command executed: /usr/local/bin/ansible all --args "backup=yes backup_options={'dir_path':'/backup'}" --extra-vars {"ansible_become":"yes","ansible_become_method":"enable","ansible_connection":"ansible.netcommon.network_cli","ansible_network_os":"eos"} --inventory X.X.X.X, --module-name eos_config --connection ansible.netcommon.network_cli

ansible: error: unrecognized arguments: ansible_become_method:enable ansible_connection:ansible.netcommon.network_cli ansible_network_os:eos

It seems that converting json to string just converts to plain string, not string which can be used in ad-hop command.

nguyenphituan avatar Aug 01 '22 12:08 nguyenphituan