logo
down
shadow

Ansible - with_dict: dictionary - How to use variables defined in each dictionary which depends upon others


Ansible - with_dict: dictionary - How to use variables defined in each dictionary which depends upon others

By : Xexrel Fenix
Date : November 22 2020, 02:59 PM
To fix the issue you can do I believe the best way to do what you want (since I don't believe loop variables can reference themselves) would be to have your task be:
code :
- name: Download Java/JDK Versions
  command: wget -q "{{ artifactory_url }}/{{ item.value.group_path }}/{{ item.value.version }}/jdk-{{item.value.version }}-{{ item.value.classifier }}-{{ item.value.ext }}"
    chdir="{{ common_download_dir }}"
    creates="{{ common_download_dir }}/jdk-{{item.value.version }}-{{ item.value.classifier }}-{{ item.value.ext }}"
  with_dict: "{{ java_versions }}"
  become_user: "{{ build_user }}"


Share : facebook icon twitter icon
Ansible with_dict expects a dict - blank Null dictionary variable

Ansible with_dict expects a dict - blank Null dictionary variable


By : Jason Todd
Date : March 29 2020, 07:55 AM
it fixes the issue The default() filter returns the default value only if the var is undefined.
http://jinja.pocoo.org/docs/2.9/templates/#default
code :
slave_nfsmount: {}
How to check whether variable is defined, when dictionary may be missing in ansible/j2

How to check whether variable is defined, when dictionary may be missing in ansible/j2


By : Antonio Sánchez Fern
Date : March 29 2020, 07:55 AM
it should still fix some issue Your conditional from "P.S." won't work for the same reason that your original one doesn't.
You'd need to use separate conditionals in nested statements:
code :
{% if haproxy.frontend is defined %}
  {%- if haproxy.frontend.web is defined %}
    {%- if haproxy.frontend.web.maxconn is defined %}
      maxconn {{ haproxy.frontend.web.maxconn }}
    {%- endif %}
  {%- endif %}
{% endif %}"
{% if ((haproxy.frontend|default({})).web|default({})).maxconn is defined %}
    maxconn {{ haproxy.frontend.web.maxconn }}
{% endif %}"
{% if 'maxconn' in (haproxy.frontend|default({})).web|default({}) %}
    maxconn {{ haproxy.frontend.web.maxconn }}
{% endif %}"
How to pass extra variables to ansible as list of dictionary to ansible playbook by --extra-vars?

How to pass extra variables to ansible as list of dictionary to ansible playbook by --extra-vars?


By : user2105824
Date : March 29 2020, 07:55 AM
will help you Just use JSON string syntax: Ansible doc. For example:
$ play.yml
code :
---
- hosts: localhost
  gather_facts: no
  tasks:
    - debug:
        msg: "This is {{ test[0] }}"

    - debug:
        msg: "This is {{ test[1] }}"
[3sky@t410 testing]$ ansible-playbook play.yml -e '{"test":["1.23.45", "12.12.12"]}'
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


PLAY [localhost] ********************************************************************************

TASK [debug] ********************************************************************************
ok: [localhost] => {
    "msg": "This is 1.23.45"
}

TASK [debug] ********************************************************************************
ok: [localhost] => {
    "msg": "This is 12.12.12"
}

PLAY RECAP ********************************************************************************
localhost     
Ansible Dictionary Variables Definition

Ansible Dictionary Variables Definition


By : Birju
Date : March 29 2020, 07:55 AM
it fixes the issue No, myvars.var1.name: test1 is not valid syntax in ansible. The variable names should not include dots.
As per documentation, https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html
Ansible - hide with_dict variables from playbook output

Ansible - hide with_dict variables from playbook output


By : JCastle720
Date : March 29 2020, 07:55 AM
like below fixes the issue Use loop_control:
code :
tasks:
  - name: "Install License and Remove Default Identifier"
    include_tasks: includes/junos_license.yml
    with_dict: "{{ vsrx }}"
    loop_control:
      label: "{{ item.key }}"
shadow
Privacy Policy - Terms - Contact Us © animezone.co