Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multiple choice variable to specify folder rights in Ansible Tower

I have a playbook that creates a directory in Ansible Tower.
I have a survey with a multiple choice options to choose the permission for this folder.

The playbook is:

- name: Create a directory
  hosts: localhost
  become_user: root
  tasks:
    - name: Create directory
      file:
        path: /test
        state: directory
        mode: u={{ user_perm }},g={{ group_perm }},o={{ other_perm }}
        owner: 'root'
        group: 'root'

When I execute the template in Ansible Tower I have to specify in the survey, via a multiple choice, the parameters: r, w, x. My intention is that I could combine this variables: rw, r, rx.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

After specifying the parameters in multiple choice the summary that Tower shows:

user_perm:
  - r
group_perm:
  - r
  - w
other_perm:
  - x

And the error message:

bad symbolic permission for mode: u=[‘r’], "gid": 0, "group": "root", "mode": "0750", "msg": "mode must be in octal or symbolic form""

Should I change the way the playbook handle variables?

>Solution :

Since a valid set of permission matching your example would be

mode: u=r,g=rw,o=x

You can simply join your lists:

mode: >-
  u={{ user_perm | join -}}
  ,g={{ group_perm | join -}}
  ,o={{ other_perm | join }}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading