Pass array in –extra-vars

To answer your first question, “How can I pass YAML array to --extra-vars in Ansible playbook.”: you can pass a JSON formatted string to extra-vars.

Here is an example play:

- hosts: all
  gather_facts: no
  tasks:
    - debug: 
        var: test_list

And how to pass the variable test_list to the command ansible-playbook:

ansible-playbook \
  test.yml \
  --connection local \ 
  --inventory localhost, \ 
  --extra-vars="{"test_list": [1,2,3]}"

Though you can use a variable for hosts I recommend checking out Ansible’s mechanism for host management which is inventory in conjunction with the --limit option.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)