如何将用户分配给ansible中的组?

How assign user to group in ansible?

我需要使用 Ansible 的哪个模块来执行此操作?

chown -R vmail:vmail /var/mail

谢谢!

您需要使用文件模块,更多信息请见Ansible file module documentation

那里的例子:

- name: Recursively change ownership of a directory
  file:
    path: /etc/foo
    recurse: yes
    owner: foo
    group: foo

使用file模块并确保设置

  state: directory

, 因为 recurse: yes

"Recursively set the specified file attributes on directory contents. This applies only when state is set to directory."

- file:
    state: directory
    path: /var/mail
    recurse: yes
    owner: vmail
    group: vmail