I've opened an issue at Ansible GitHub and got explained how argv parameter 
works.
https://github.com/ansible/ansible/issues/79967

Summary:
This happens because of how module and redis-cli utility work with 
arguments.
When passing arguments this modules delimits them with single quotation 
marks, so
    - name: Create Redis cluster
      ansible.builtin.command:
        argv:
          - /usr/bin/redis-cli
          - "--user {{ redis_admin_user }}"
          - "--pass {{ redis_admin_password }}"
          - "--cluster create {{ redis_cluster_members }}"
          - "--cluster-replicas {{ redis_cluster_replicas }}"
          - --cluster-yes

is passed as (mind the quotation marks)
/usr/bin/redis-cli '--user admin' '--pass mypass' '--cluster create 
10.226.2.194:6379 10.226.2.196:6379 10.226.2.195:6379' '--cluster-replicas 
1' '--cluster-yes'

If you enter this command directly into command line you'll get the same 
error - "Unrecognized option or bad number of args for: '--user admin'".

This is because, quoting redis-cli documentation 
(https://redis.io/docs/ui/cli/#string-quoting-and-escaping),
> When redis-cli parses a command, whitespace characters automatically 
delimit the arguments. 

So the correct way to pass this command will be (mind the quotation marks)
/usr/bin/redis-cli '--user' 'admin' '--pass' 'mypass' '--cluster' 'create ' 
'10.226.2.194:6379' '10.226.2.196:6379' '10.226.2.195:6379' 
'--cluster-replicas' '1' '--cluster-yes' 

So I did a workaround constructing the command as a variable in 
vars/main.yml and then passing it to the module (I'm going to post it on 
stackoverflow).
четверг, 9 февраля 2023 г. в 17:06:24 UTC+3, Rowe, Walter P. (Fed): 

> I had a problem similar to this once. Your redis command might be getting 
> your cluster members as a single string vs separate ip:port args.
>
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123 <(202)%20355-4123>
>
> On Feb 9, 2023, at 8:57 AM, tariver 16 <[email protected]> wrote:
>
> Thank you for your reply
>
> Changed the shell script to the following:
>
> #!/bin/sh
> ansible-playbook /etc/ansible/playbook-redis.yml -vv \
> --extra-vars "redis_admin_user=admin redis_admin_password=mypass" \
> --extra-vars "redis_cluster_members='10.226.2.194:6379 10.226.2.196:6379 
> 10.226.2.195:6379'" \
> --extra-vars "redis_cluster_replicas=1"
>
> Got the same error "Unrecognized option or bad number of args for: 
> '--cluster create'"
> четверг, 9 февраля 2023 г. в 16:00:41 UTC+3, [email protected]: 
>
>> #!/bin/sh ansible-playbook /etc/ansible/playbook-redis.yml -vv \
>> --extra-vars*=*'redis_admin_user=admin redis_admin_password=mypass' \
>> --extra-vars*=*'redis_cluster_members="10.226.2.194:6379 
>> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2F10.226.2.194%3A6379%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RabFEhs%2Byns3GLbZ4NLXSEGrWnkU1E%2FIk2PLNyE2N5g%3D&reserved=0>
>>  10.226.2.196:6379 
>> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2F10.226.2.196%3A6379%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=KGvfPsbNuxjHIMIk67R%2BruOjTk0EIpOg91U%2FAsPdy4k%3D&reserved=0>
>>  10.226.2.195:6379 
>> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2F10.226.2.195%3A6379%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=R5f2SP8L7TupRSehncgFrNkbxZRsGO%2F%2BSlQy6sfkr4Q%3D&reserved=0>"
>>  
>> redis_cluster_replicas=1'
>>
>>
>> Leave off the = and use a space for --extra_vars. 
>>
>>   -e EXTRA_VARS, --extra-vars EXTRA_VARS
>>                         set additional variables as key=value or 
>> YAML/JSON, if filename prepend with @
>>
>> Walter
>> --
>> Walter Rowe, Division Chief
>> Infrastructure Services, OISM
>> Mobile: 202.355.4123 <(202)%20355-4123>
>>
>> On Feb 9, 2023, at 7:01 AM, tariver 16 <[email protected]> wrote:
>>
>> Greeting!
>> Asked it on stackoverflow 
>> <https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F75388765%2Fhow-can-i-pass-variables-to-command-modules-argv-parameter-in-ansible&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2Bqhaj0g%2BrvVlCjlTWOyFJecozZwFeLSosmvt4b7J%2BQs%3D&reserved=0>,
>>  
>> but didn't get an answer, so I'm trying my luck here.
>>
>> A bit condensed version:
>> I'm trying to write a role that creates a Redis cluster. At some point I 
>> must execute redis-cli binary with some parameters:
>>
>> /usr/bin/redis-cli --user admin --pass mypass --cluster create 
>> 10.226.2.194:6379 
>> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2F10.226.2.194%3A6379%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RabFEhs%2Byns3GLbZ4NLXSEGrWnkU1E%2FIk2PLNyE2N5g%3D&reserved=0>
>>  10.226.2.196:6379 
>> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2F10.226.2.196%3A6379%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=KGvfPsbNuxjHIMIk67R%2BruOjTk0EIpOg91U%2FAsPdy4k%3D&reserved=0>
>>  10.226.2.195:6379 
>> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2F10.226.2.195%3A6379%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=R5f2SP8L7TupRSehncgFrNkbxZRsGO%2F%2BSlQy6sfkr4Q%3D&reserved=0>
>>  --cluster-replicas 1 --cluster-yes 
>>
>> I pass all the required parameters as extra variables when I call the 
>> playbook with a shell script:
>>
>> #!/bin/sh ansible-playbook /etc/ansible/playbook-redis.yml -vv \
>> --extra-vars='redis_admin_user=admin redis_admin_password=mypass' \
>> --extra-vars='redis_cluster_members="10.226.2.194:6379 
>> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2F10.226.2.194%3A6379%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RabFEhs%2Byns3GLbZ4NLXSEGrWnkU1E%2FIk2PLNyE2N5g%3D&reserved=0>
>>  10.226.2.196:6379 
>> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2F10.226.2.196%3A6379%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=KGvfPsbNuxjHIMIk67R%2BruOjTk0EIpOg91U%2FAsPdy4k%3D&reserved=0>
>>  10.226.2.195:6379 
>> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2F10.226.2.195%3A6379%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=R5f2SP8L7TupRSehncgFrNkbxZRsGO%2F%2BSlQy6sfkr4Q%3D&reserved=0>"
>>  
>> redis_cluster_replicas=1'
>>
>> At first I tried the following:
>>
>> - name: Create Redis cluster
>>   ansible.builtin.command:
>>     argv:
>>       - /usr/bin/redis-cli
>>       - "--user {{ redis_admin_user }}"
>>       - "--pass {{ redis_admin_password }}"
>>       - "--cluster create {{ redis_cluster_members }}"
>>       - "--cluster-replicas {{ redis_cluster_replicas }}"
>>       - --cluster-yes
>>
>> And got error "Unrecognized option or bad number of args for: '--user 
>> admin'" which is a redis-cli error.
>>
>> After some experimenting I found out that if I pass the variables in a 
>> separate line some of them work. So this task works and returns info about 
>> server.
>>
>> - name: Get server info
>>   ansible.builtin.command:
>>     argv:
>>       - /usr/bin/redis-cli
>>       - --user
>>       - "{{ redis_admin_user }}"
>>       - --pass
>>       - "{{ redis_admin_password }}"
>>       - info 
>>
>> So the username and password are recognized be redis-cli, but, 
>> unfortunately not the "redis_cluster_members". The following task:
>>
>> - name: Create Redis cluster
>>   ansible.builtin.command:
>>     argv:
>>       - /usr/bin/redis-cli
>>       - --user
>>       - "{{ redis_admin_user }}"
>>       - --pass
>>       - "{{ redis_admin_password }}"
>>       - --cluster create
>>       - "{{ redis_cluster_members }}"
>>       - --cluster-replicas
>>       - "{{ redis_cluster_replicas }}"
>>       - --cluster-yes 
>>
>> returns error "Unrecognized option or bad number of args for: '--cluster 
>> create'"
>>
>> I wonder if I'm missing some syntax error or misread the documentation 
>> and trying to use argv not the way it's supposed to be used?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/18d93d65-bd16-45d1-a813-9be828ffed68n%40googlegroups.com
>>  
>> <https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F18d93d65-bd16-45d1-a813-9be828ffed68n%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=eVoCEGw7rn7%2FtNDgbyagWFna2b4jhywDmqvhqbWnU0s%3D&reserved=0>
>> .
>>
>>
>>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
>
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/e7cee569-acb1-4e19-9d7f-39331b730ff2n%40googlegroups.com
>  
> <https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2Fe7cee569-acb1-4e19-9d7f-39331b730ff2n%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7C455814b1802d4f2a6a0308db0aa5d76d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638115479632041406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=39v8lQIvS1OmnAEOTzcD54Sb5gxhjhumUfJs7GqjkRk%3D&reserved=0>
> .
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/16dd90bd-4748-4eab-a6e0-877a750951a2n%40googlegroups.com.

Reply via email to