# Strip doube quotes from list

**URL:** <https://forum.ansible.com/t/strip-doube-quotes-from-list/10497>\
**Category:** Get Help\
**Tags:** playbook\
**Created:** [October 24, 2024, 10:06pm UTC](https://forum.ansible.com/t/strip-doube-quotes-from-list/10497 "2024-10-24T22:06:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sturnisvulgaris](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@sturnisvulgaris](https://forum.ansible.com/u/sturnisvulgaris)\
**Post date:** [October 24, 2024, 10:06pm UTC](https://forum.ansible.com/t/strip-doube-quotes-from-list/10497/1 "2024-10-24T22:06:58Z")

</div>

I need help stripping the " " from around the joined list.

```auto
vars:
 sox_files:
        - '/etc/login.defs'
        - '/etc/default/useradd'
        - '/etc/passwd'
        - '/etc/shadow'
        - '/etc/group'
        - '/etc/hosts'
        - '/etc/audit/auditd.conf'
    
     - name: Join the list of strings
       debug:
        msg: "{{ sox_files | join(' ') }}"
       tags: bug

     - name: Compress into archive
       ansible.builtin.shell:
          cmd: |
            zip /tmp/sox/audit.zip "{{ sox_files | join(' ') }}"

```

When I run the playbook the zip command fails because the list of files is encapsulated in quotes.

TASK [Join the list of strings] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [testhost] =\> {  
“msg”: “/etc/login.defs /etc/default/useradd /etc/passwd /etc/shadow /etc/group /etc/hosts /etc/audit/auditd.conf”  
}

TASK [Compress into archive] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [testhost]: FAILED! =\> {“changed”: true, “cmd”: “zip /tmp/sox/audit.zip "/etc/login.defs /etc/default/useradd /etc/passwd /etc/shadow /etc/group /etc/hosts /etc/audit/auditd.conf"\n”, “delta”: “0:00:00.005151”, “end”: “2024-10-24 18:00:48.138459”, “msg”: “non-zero return code”, “rc”: 12, “start”: “2024-10-24 18:00:48.133308”, “stderr”: “”, “stderr\_lines”: , “stdout”: “\tzip warning: name not matched: /etc/login.defs /etc/default/useradd /etc/passwd /etc/shadow /etc/group /etc/hosts /etc/audit/auditd.conf\n\nzip error: Nothing to do! (/tmp/sox/audit.zip)”, “stdout\_lines”: [“\tzip warning: name not matched: /etc/login.defs /etc/default/useradd /etc/passwd /etc/shadow /etc/group /etc/hosts /etc/audit/auditd.conf”, “”, “zip error: Nothing to do! (/tmp/sox/audit.zip)”]}

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [October 24, 2024, 10:45pm UTC](https://forum.ansible.com/t/strip-doube-quotes-from-list/10497/2 "2024-10-24T22:45:08Z")

</div>

Hii

> > ![](https://us1.discourse-cdn.com/ansible/original/2X/a/ad35f4a944ebff1f93e7718ff7500ee62a87df73.png "sturnisvulgaris") | [sturnisvulgaris](http://forum.ansible.com/u/sturnisvulgaris) Michael  
> > October 24 |
> > 
> > - | - |
> 
> I need help stripping the " " from around the joined list.
> 
> ```auto
> vars:
> sox_files:
> - '/etc/login.defs'
> - '/etc/default/useradd'
> - '/etc/passwd'
> - '/etc/shadow'
> - '/etc/group'
> - '/etc/hosts'
> - '/etc/audit/auditd.conf'
>     
> - name: Join the list of strings
> debug:
> msg: "{{ sox_files | join(' ') }}"
> tags: bug
> 
> - name: Compress into archive
> ansible.builtin.shell:
> cmd: |
> zip /tmp/sox/audit.zip "{{ sox_files | join(' ') }}"
> 
> ```
> 
> When I run the playbook the zip command fails because the list of files is encapsulated in quotes

That is because you asked it to encapsulate it in quotes 🙂  
If you remove them, it will work.  
But, there are still two issues then. One is that arguments without any escaping/quote is fragile, so it will break with filename that have spaces, quotes, etc.  
The other problem is that you’re using a shell module for something that a real ansible module can do.  
This is simpler to use and less error prone:

- name: compress with ansible  
community.general.archive:  
dest: /tmp/sox2.zip  
path: “{{ sox\_files }}”  
format: zip

---

<div class="post-metadata">

**Author:** ![sturnisvulgaris](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@sturnisvulgaris](https://forum.ansible.com/u/sturnisvulgaris)\
**Post date:** [October 25, 2024, 12:26pm UTC](https://forum.ansible.com/t/strip-doube-quotes-from-list/10497/3 "2024-10-25T12:26:40Z")

</div>

> [@dnmvisser](#):
>
> community.general.archive:  
> dest: /tmp/sox2.zip  
> path: “{{ sox\_files }}”  
> format: zip

Thank you. I had to install the community modules first.
