Bug 1896473

Summary: '--ansible-extra-vars=' doesn't parse correctly when there are spaces in the value argument
Product: [oVirt] otopi Reporter: Asaf Rachmani <arachman>
Component: GeneralAssignee: Yedidyah Bar David <didi>
Status: CLOSED WONTFIX QA Contact: Nikolai Sednev <nsednev>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 1.9.2CC: bugs
Target Milestone: ---Flags: pm-rhel: ovirt-4.4+
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-11-19 11:19:07 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Integration RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1820146    

Description Asaf Rachmani 2020-11-10 16:15:01 UTC
Description of problem:
Parse doesn't work correctly when running hosted-engine deploy with '--ansible-extra-vars=DATA' if the DATA is var=value and the 'value' contains spaces. 

Version-Release number of selected component (if applicable):
ovirt-hosted-engine-setup-2.4.8
python3-otopi-1.9.2-1.el8.noarch

How reproducible:
100%

Steps to Reproduce:
1. Run hosted-engine --deploy --ansible-extra-vars=he_cluster_cpu_type="Intel SandyBridge Family"

Actual results:
HE deployment fails with the following error:

./ovirt-hosted-engine-setup-20201110134130-0adum8.log:199:2020-11-10 13:41:30,516+0000 DEBUG otopi.context context.dumpEnvironment:775 ENV OVEHOSTED_CORE/ansibleUserExtraVars=str:'he_cluster_cpu_type=Intel'


Expected results:
HE deployment succeeds

Comment 1 Yedidyah Bar David 2020-11-11 07:03:42 UTC
(In reply to Asaf Rachmani from comment #0)
> Actual results:
> HE deployment fails with the following error:
> 
> ./ovirt-hosted-engine-setup-20201110134130-0adum8.log:199:2020-11-10
> 13:41:30,516+0000 DEBUG otopi.context context.dumpEnvironment:775 ENV
> OVEHOSTED_CORE/ansibleUserExtraVars=str:'he_cluster_cpu_type=Intel'

This is not the error, right? I assume the error is later, when the code
checking this var sees that there is no cpu type called 'Intel'.

Pushed a trivial patch that solves this, but not sure it's impossible
to still pass values that cause parsing errors somehow.

Workaround: Put the data in a file, pass it as '@file'.

Comment 2 Yedidyah Bar David 2020-11-11 07:50:02 UTC
This patch is not enough, and I prefer to close wontfix.
Please use '@varfile' if needed.

Details:

There are several layers of passing arguments around: otopi (a shell script) -> otopi's python code (which has its own trivial parser) -> ansible-playbook (a shell script as well) -> ansible's python code (uses argparse and some python code).

Some of these layers even do not explicitely document how parsing/whitespace/etc works, e.g.:

https://stackoverflow.com/questions/41475446/ansible-playbook-extra-vars-with-a-space-in-a-value

https://stackoverflow.com/questions/18157376/handle-spaces-in-argparse-input

Currently-linked patch "fixes" the symptom detailed in comment 0 (otopi's log shows in the env dump the expected output), but is not enough for doing this in ansible, and so is basically useless.

Comment 3 Yedidyah Bar David 2020-11-11 07:52:03 UTC
Asaf, is there a concrete reason for needing to pass this value? If so, is the workaround (use '@varfile') enough?

Comment 4 Asaf Rachmani 2020-11-15 07:45:02 UTC
(In reply to Yedidyah Bar David from comment #3)
> Asaf, is there a concrete reason for needing to pass this value? If so, is
> the workaround (use '@varfile') enough?

Yes, please have a look at bug 1820146.
I tried the workaround, but it also didn't work for me.

hosted-engine --deploy --ansible-extra-vars='@a.json'
...
          Please indicate the gateway IP address [192.168.155.1]: 
[ ERROR ] b'ERROR! Unable to retrieve file contents\n'
[ ERROR ] b"Could not find or access '/a.json' on the Ansible Controller.\n"
[ ERROR ] b'If you are using a module and expect the file to exist on the remote, see the remote_src option\n'
[ ERROR ] Failed to execute stage 'Environment customization': Failed executing ansible-playbook
[ INFO  ] Stage: Clean up 

When I remove the '@' from the varfile, deployment finished but didn't use 'he_cluster_cpu_type' var.

Comment 5 Yedidyah Bar David 2020-11-15 08:35:43 UTC
(In reply to Asaf Rachmani from comment #4)
> (In reply to Yedidyah Bar David from comment #3)
> > Asaf, is there a concrete reason for needing to pass this value? If so, is
> > the workaround (use '@varfile') enough?
> 
> Yes, please have a look at bug 1820146.
> I tried the workaround, but it also didn't work for me.
> 
> hosted-engine --deploy --ansible-extra-vars='@a.json'
> ...
>           Please indicate the gateway IP address [192.168.155.1]: 
> [ ERROR ] b'ERROR! Unable to retrieve file contents\n'
> [ ERROR ] b"Could not find or access '/a.json' on the Ansible Controller.\n"

Not sure what causes it to search "/", but using a full path seems to work for me:

hosted-engine --deploy --ansible-extra-vars=@/root/a.json

Good enough?

Comment 6 Asaf Rachmani 2020-11-19 10:46:55 UTC
(In reply to Yedidyah Bar David from comment #5)
> (In reply to Asaf Rachmani from comment #4)
> > (In reply to Yedidyah Bar David from comment #3)
> > > Asaf, is there a concrete reason for needing to pass this value? If so, is
> > > the workaround (use '@varfile') enough?
> > 
> > Yes, please have a look at bug 1820146.
> > I tried the workaround, but it also didn't work for me.
> > 
> > hosted-engine --deploy --ansible-extra-vars='@a.json'
> > ...
> >           Please indicate the gateway IP address [192.168.155.1]: 
> > [ ERROR ] b'ERROR! Unable to retrieve file contents\n'
> > [ ERROR ] b"Could not find or access '/a.json' on the Ansible Controller.\n"
> 
> Not sure what causes it to search "/", but using a full path seems to work
> for me:
> 
> hosted-engine --deploy --ansible-extra-vars=@/root/a.json
> 
> Good enough?

Yes, good enough for me.
We just need to make sure it's properly documented.

Comment 7 Yedidyah Bar David 2020-11-19 11:19:07 UTC
Not sure where best to document this. People do not read documentation...

I hope they'll find current bug and this should be enough.

For this specific case (spaces in values), now verified that this workaround works as well:

hosted-engine --deploy --ansible-extra-vars='ansvar1=\"val1\ val2\"'

Didn't try with he_cluster_cpu_type, just checked ansible logs, and they indicate the value arrived well:

2020-11-19 13:12:59,454+0200 DEBUG var changed: host "localhost" var "ansvar1" type "<class 'str'>" value: ""val1 val2""

Generally, it's better to put the values in an ansible var file, and pass it using '@file'. When you do, please note that you need to pass a full path to the file.

Currently closing wontfix.

If someone wants to reopen, we should first open a bug on ansible, to support (or at least document) passing such values on its command line.

Or instead we can cheat and write the value to a temp file and pass it to ansible with '@', but I do not think this is worth it.