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
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/>"\*
* - 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é
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 .