当用户在特定组中时创建目录

Directory creation when user is in specific group

我正在尝试执行以下任务,如果用户是 hdfsuser 组的一部分,则创建一个目录

- include_vars: ../../security/vars/main.yml 

- name: create user tmp dir /srv/tmp/$USER on gateway
  file: path=/srv/tmp/{{ item.name }} owner={{ item.name }} group={{ item.name }} mode=0755 state=directory
  when: "'hdfsuser' in {{ item.groups }}"
  with_items: ssh_users #this is coming from - include_vars: ../../security/vars/main.yml 
  tags:
    - hadoop

但是出现这个错误:

fatal: [hadoop-client001.dev.abc.com]: FAILED! => {"failed": true, "msg": "The conditional check ''hdfsuser' in {{ item.groups }}' failed. The error was: template error while templating string: expected token ',', got 'string'. String: {% if 'hdfsuser' in [u'users'] %} True {% else %} False {% endif %}\n\nThe error appears to have been in '/Users/xyz/ansible/roles/luigi/tasks/main.yml': line 81, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: create user tmp dir /srv/tmp/$USER on gateway\n  ^ here\n"}

有人知道解决这个问题的方法吗?

when 条件已被解释为 Jinja2 表达式,因此不需要大括号。

when: "'hdfsuser' in item.groups"