# Apt behaviour

**URL:** <https://forum.ansible.com/t/apt-behaviour/36404>\
**Category:** Ansible Project\
**Created:** [March 7, 2022, 2:10am UTC](https://forum.ansible.com/t/apt-behaviour/36404 "2022-03-07T02:10:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![igorc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/igorc/32/5491_2.png) [@igorc](https://forum.ansible.com/u/igorc)\
**Post date:** [March 7, 2022, 2:10am UTC](https://forum.ansible.com/t/apt-behaviour/36404/1 "2022-03-07T02:10:49Z")

</div>

Hi all,

Anyone knows why is apt behaving differently here? I have this var

fonts\_packages:

- ttf-wqy-zenhei
- fonts-takao-mincho
- fonts-indic
- ttf-wqy-microhei

and simple task:

- name: install additional fonts  
apt:  
name: “{{ fonts\_packages }}”  
state: present

passing the list to apt.

That works in Ansible 2.4.4 as expected:

“invocation”: {  
“module\_args”: {

“name”: [  
“ttf-wqy-zenhei”,  
“fonts-takao-mincho”,  
“fonts-indic”,  
“ttf-wqy-microhei”  
],  
“only\_upgrade”: false,  
“package”: [  
“ttf-wqy-zenhei”,  
“fonts-takao-mincho”,  
“fonts-indic”,  
“ttf-wqy-microhei”  
],  
…

But in 2.5+ fails because:

fatal: [hostname]: FAILED! =\> {  
“changed”: false,  
“invocation”: {  
“module\_args”: {

“name”: “[‘ttf-wqy-zenhei’, ‘fonts-takao-mincho’, ‘fonts-indic’, ‘ttf-wqy-microhei’]”,  
“only\_upgrade”: false,  
“package”: [  
“[‘ttf-wqy-zenhei’”,  
" ‘fonts-takao-mincho’“,  
" ‘fonts-indic’”,  
" ‘ttf-wqy-microhei’]"  
],  
…  
},  
“msg”: “No package(s) matching ‘[‘ttf-wqy-zenhei’’ available”  
}

I’m passing a list to apt “name” parameter as per the documentation.

Thanks

---

<div class="post-metadata">

**Author:** ![jcpetro](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jcpetro](https://forum.ansible.com/u/jcpetro)\
**Post date:** [March 7, 2022, 2:23am UTC](https://forum.ansible.com/t/apt-behaviour/36404/2 "2022-03-07T02:23:51Z")

</div>

Usually I tend to see this when the apt cache isn’t current. I am sure there are other reasons as well, but more than 80% of the time for me, that usually fixes my issue.

–John

---

<div class="post-metadata">

**Author:** ![Rilindo\_Foster1](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Rilindo\_Foster1](https://forum.ansible.com/u/Rilindo_Foster1)\
**Post date:** [March 7, 2022, 2:41am UTC](https://forum.ansible.com/t/apt-behaviour/36404/3 "2022-03-07T02:41:51Z")

</div>

Given John’s statement, add \*update\_cache: yes”

- name: install additional fonts  
apt:  
name: “{{ fonts\_packages }}”  
state: present  
**update\_cache: yes**

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [March 7, 2022, 6:07am UTC](https://forum.ansible.com/t/apt-behaviour/36404/4 "2022-03-07T06:07:38Z")

</div>

hi,

> Hi all,
> 
> Anyone knows why is apt behaving differently here? I have this var

I don't think this is related to the apt module, but to how the  
variable ends up being loaded. It seems to end up as a string, but not  
as a sting in JSON format (which would be converted to a list), but in  
Python format.

Without knowing how exactly you end up with the variable in this format.

(Also please note that both Ansible 2.4.x and 2.5.x are completely  
outdated and End of Line.)

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![igorc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/igorc/32/5491_2.png) [@igorc](https://forum.ansible.com/u/igorc)\
**Post date:** [March 7, 2022, 7:25am UTC](https://forum.ansible.com/t/apt-behaviour/36404/5 "2022-03-07T07:25:57Z")

</div>

Of course it has everything to do with the module, what else? The 2.4.4 does the correct thing and takes the list as it is: a list. The module documentation also says it needs to be a list.

However, 2.5+ takes that list as a string for some reason and wraps it in a list ending in that silly state of a list inside a list. That can’t be right.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 28, 2022, 5:07pm UTC](https://forum.ansible.com/t/apt-behaviour/36404/6 "2022-03-28T17:07:59Z")

</div>

It is not the module, but the data passed into it, for some reason the engine is taking it as a string, try adding |list to the expression:

name: “{{ fonts\_packages|list }}”

---

<div class="post-metadata">

**Author:** ![omodotun\_Babatope](https://avatars.discourse-cdn.com/v4/letter/o/58956e/32.png) [@omodotun\_Babatope](https://forum.ansible.com/u/omodotun_Babatope)\
**Post date:** [March 28, 2022, 5:08pm UTC](https://forum.ansible.com/t/apt-behaviour/36404/7 "2022-03-28T17:08:58Z")

</div>

Hi Brian,

How is it going. thanks for your email.  
let me quickly try that out and get back to you.

Best Regards.  
Dotun
