简体   繁体   中英

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 .

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?

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 }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM