On 5/24/21 3:46 PM, Manoj Chander wrote:
> Greetings  André,
> 
> Thanks you so much for ur time. 
> 
> The above solution works but i have some 100 jars to download .
> 
> Is it possible  to set_fact  in a loop store the constructed variable  in a 
> list and pass it to  *get_url*  method .  
> 
> ---
> - include_vars:
>    file: vars.yml
> - set_fact:
>     b_url: http://{{item}}/sr/pr/
>  # jar is a list in vars.yml
>  loop: "{{ jars }}" 
>  register: b_url 
> - debug:
>     msg: "no of sites are ==>   {{ b_url  }}  "
> - name: Container Checks
>  block:
>        - name: download "{{file }}"
>          get_url:
>            url:  "{{ item }}"
>            dest: "/manual/jar/"
>    loop: {{b_url}}
> 

Hello Manoj,

1) Using register in a set_fact task doesn't make sense, as set_fact is 
supposed to set the
   variables.

2) Do you really need to use set_fact?

  - name: download "{{file }}"
    get_url:
      url: "http://{{item}}/sr/pr/";
      dest: "/manual/jar/"
    loop: "{{ jars }}"

Regards
         Racke

> regards,
> Manoj
> 
> On Friday, May 21, 2021 at 11:39:29 AM UTC+5:30 André Liebigt wrote:
> 
>     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] 
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/9482dd18-ae18-40db-a254-6fc936adbb93n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/9482dd18-ae18-40db-a254-6fc936adbb93n%40googlegroups.com?utm_medium=email&utm_source=footer>.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
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/7d40df1e-238c-0b8a-f867-25e147ec8f92%40linuxia.de.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to