<p>I probably should use comment instead group the value in a dict who's value is a list</p>

<p>like</p>

<pre><code>packages:
  - apt-file
  - axel
  - ibus-rime
  - rofi
  - i3
  - ffmpeg
  - xclip
  - cargo
  - httpie
  - ttf-ubuntu-font-family
  - tldr-py
  - glances
  # browsers:
  - brave-browser
  - chromium
  # editors
  - emacs
</code></pre>

CC BY-SA 4.0
2020-06-17T07:31:18.923Z
2020-06-17T07:31:18.923Z
Roy
<p>I have a variable named packages as showed below, it is not a plain list, I have some nested dict in it like browsers.</p>

<pre class="lang-yaml prettyprint-override"><code>
--- 
packages:
  - apt-file
  - axel
  - ibus-rime
  - rofi
  - i3
  - ffmpeg
  - xclip
  - cargo
  - httpie
  - ttf-ubuntu-font-family
  - tldr-py
  - glances
  - browsers:
    - brave-browser
    - chromium
  - editors:
    - emacs
</code></pre>

<p>I'd like to use instructions like below</p>

<pre><code>- name: Install a list of packages
    become: yes
    apt:
        name: "{{ packages }}"
</code></pre>

<p>to install all the pacakges defined in the variable, but I do not know what filter I should use the convert the variable to plain list, I need the items in the nested dictionary.</p>

<p>any help will be appreciated.</p>

CC BY-SA 4.0
2020-06-16T00:43:36.077Z
Please provide an example var definition that is valid yaml. Your current example cannot be parsed so no one can understand the exact data structure you want to use. Note that the problem also exists for your example task (but it is a little easier to guess).
Zeitounator
<ansible>
How do a flaten a list mixed with nested dict in ansible playbook?
Roy
# How do a flaten a list mixed with nested dict in ansible playbook?

(Asked by: username_0 on 2020-05-27)

I have a variable named packages as showed below, it is not a plain list, I have some nested dict in it like browsers.

--- 
packages:
  - apt-file
  - axel
  - ibus-rime
  - rofi
  - i3
  - ffmpeg
  - xclip
  - cargo
  - httpie
  - ttf-ubuntu-font-family
  - tldr-py
  - glances
  - browsers:
    - brave-browser
    - chromium
  - editors:
    - emacs

I'd like to use instructions like below
- name: Install a list of packages
    become: yes
    apt:
        name: "{{ packages }}"

to install all the pacakges defined in the variable, but I do not know what filter I should use the convert the variable to plain list, I need the items in the nested dictionary.
any help will be appreciated.

**Tags:** ansible

> **Comments:**
> **username_1**: Please provide an example var definition that is valid yaml. Your current example cannot be parsed so no one can understand the exact data structure you want to use. Note that the problem also exists for your example task (but it is a little easier to guess).  

---

## 1 answers

### Answer by username_0 on 2020-06-17. Score: 1

I probably should use comment instead group the value in a dict who's value is a list
like
packages:
  - apt-file
  - axel
  - ibus-rime
  - rofi
  - i3
  - ffmpeg
  - xclip
  - cargo
  - httpie
  - ttf-ubuntu-font-family
  - tldr-py
  - glances
  # browsers:
  - brave-browser
  - chromium
  # editors
  - emacs


---

