Greeting!
Asked it on stackoverflow 
<https://stackoverflow.com/questions/75388765/how-can-i-pass-variables-to-command-modules-argv-parameter-in-ansible>,
 
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 10.226.2.196:6379 10.226.2.195:6379 --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 10.226.2.196:6379 
10.226.2.195:6379" 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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/18d93d65-bd16-45d1-a813-9be828ffed68n%40googlegroups.com.

Reply via email to