'How can I provide multiple value in a variable using, separator - Ansible playbook

 - name: Application deployment
    hosts: "{{ target_hosts }}"
    gather_facts: no
    become: yes
    become_method: su
    become_user: 'root'
    roles:
    - APP_deployment 
    vars:
      - password_supersu: 'Abcdefg@Linux'
      - ansible_su_pass: 'Abcdefg@Linux' 

    vars_prompt:
    - name: "target_hosts"
      prompt: "Please input the Target Host name:"
      default: ""
      private: no
    - name: "war_name"
      prompt: "Please input the War files name:"
      default: ""
      private: no
    - name: "chksum_src"
      prompt: "Please input the MD5chksum value :"
      default: ""

   tasks: 
   - add_hosts:
         name: ""{{target_hosts}}""
         groups: dynamically_created_hosts

   - with_iteams: 
         ""{{ war_name. split (',') }}""
         ""{{ chksum_src. split (',') }}""

Using this playbook I can target multiple host using, separator but if I want to use the same for war name and Md5chksum value also.

In simple I want to deploy multiple files to multiple host with chksum value check, the task are defined in roles already but is it possible to separate the chksum value and files name as well.

Thanks in Advance



Solution 1:[1]

Regarding your question about Variables and how to

provide multiple value in a variable using comma (,) separator

it seems a List will be the solution.

['war_file_1', 'war_file_2', 'war_file_3']

It looks you like to append to a list and do something similar

- name: Add WAR files
  set_fact:
    WAR_FILES: "{{ WAR_FILES + [item] }}"
  with_items: "{{ war_names.split(',') | list }}"

As you mentioned the add_host module already, you may have a look into Add a host (and alternatively a group) to the ansible-playbook in-memory inventory and the Examples. The syntax would than be like

- name: Add hosts to the 'dynamically_created_hosts' group
  add_host:
    name: '{{ item }}'
    groups: dynamically_created_hosts
  loop: "{{ target_hosts }}"

Thanks also to

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1