Hi, for this to work artifacturl always needs to be a list. A first attempt could look like this:
*---* *- name: Block to Deploy on Servers* * block:* * - set_fact:* * artifact_url: "https://my.url <https://my.url/>"* * - set_fact:* * group_id: "{% if app_name == 'group1' %}/com/connectors/{% elif app_name == 'group2' %}* * /com/connectors/{% else %}/com/services/{% endif %}"* * register: group_id * * - set_fact:* * artifacturls: * * - "{ artifact_url }}{{ group_id }}jar1/{{ app_version }}/{{ item }}-{{ app_version }}.jar"* *- "{ artifact_url }}{{ group_id }}jar2/{{ app_version }}/{{ item }}-{{ app_version }}.jar"* * when: app_name == group2* * - set_fact:* * artifacturls: * * - "{ artifact_url }}{{ group_id }}{{ app_name }}/{{ app_version }}/{{ app_name }}-{{ app_version }}.jar"* * when: app_name != group2* *pass the constructed variable to another block * *- name: Block to get file "{{app_name}}"* * block:* * - name: download "{{app_name}}" form url* * get_url:* * url: "{{ item }}"* * dest: "/manual/{{ app_name }}.jar"* * loop:* * - {{ artifacturls }}* This leads to a bit of duplication for group2 which could be omitted by a more complex construct like this: * - set_fact:* * artifacturls: "({{ artifact_urls | default([])) + {{ artifact_url }}{{ group_id }}{{ item }}/{{ app_version }}/{{ item }}-{{ app_version }}.jar"* * when: app_name == group2* * loop:* * - jar1* * - jar2 * Hope that helps, André On Thursday, May 20, 2021 at 12:43:07 PM UTC+2 [email protected] wrote: > > Hi , > > Im a newbie learnig ansible .im stuck with the below > > > *I need to get input from user and based on input dynamically create a > url .* > > *input group1 is a single value and group2 is a list * > > *using with_items and loop im able to create variable but couldnt > register it and pass it to get_url module . below is one of my failed > attempts .* > > *ansible-playbook -e "app_name=group1 or app_name=group2 ...."* > > *---* > *- name: Block to Deploy on Servers* > * block:* > * - set_fact:* > * artifact_url: "https://my.url <https://my.url>"* > * - set_fact:* > > * group_id: "{% if app_name == 'group1' %}/com/connectors/{% > elif app_name == 'group2' %}* > * /com/connectors/{% else %}/com/services/{% endif %}"* > * register: group_id * > > * - set_fact:* > * artifacturl: "{ artifact_url }}{{ group_id }}{{ item }}/{{ > app_version }}/{{ item }}-{{ app_version }}.jar"* > * when: app_name == group2* > * loop:* > * - jar1* > * - jar2 * > * register: artifacturl* > * - set_fact:* > * artifacturl: "{ artifact_url }}{{ group_id }}{{ app_name > }}/{{ app_version }}/{{ app_name }}-{{ app_version }}.jar"* > * when: app_name != group2* > > *pass the constructed variable to another block * > > *- name: Block to get file "{{app_name}}"* > * block:* > * - name: download "{{app_name}}" form url* > * get_url:* > * url: "{{ artifacturl }}"* > * dest: "/manual/{{ app_name }}.jar"* > * loop:* > * - {{ artifacturl }}* > -- 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/54dc2281-c596-4a88-855c-aa8cb0143ec4n%40googlegroups.com.
