模組文件

  1. 查詢 user 模組文件。
    ceuser@deyu:~/ansible_pb$ ansible-doc user
    
  2. 查詢 user 模組文件的範例,新增帳號 johnd,且指定群組及 uid。
    ceuser@deyu:~/ansible_pb$ ansible-doc user | grep ^EX -A50
    EXAMPLES:
    
    - name: Add the user 'johnd' with a specific uid and a primary group of 'admin'
      ansible.builtin.user:
        name: johnd
        comment: John Doe
        uid: 1040
        group: admin
    
  3. 新增帳號 james,且指定群組及 shell。
    - name: Add the user 'james' with a bash shell, appending the group 'admins' 
    and 'developers' to the user's groups
      ansible.builtin.user:
        name: james
        shell: /bin/bash
        groups: admins,developers
        append: yes
    
  4. 刪除帳號 johnd。
    - name: Remove the user 'johnd'
      ansible.builtin.user:
        name: johnd
        state: absent
        remove: yes
    
  5. 新增帳號 jsmith,產生 ssh 金鑰。
    - name: Create a 2048-bit SSH key for user jsmith in ~jsmith/.ssh/id_rsa
      ansible.builtin.user:
        name: jsmith
        generate_ssh_key: yes
        ssh_key_bits: 2048
        ssh_key_file: .ssh/id_rsa
    
  6. 新增帳號 james18,設定帳戶過期時間。
    - name: Added a consultant whose account you want to expire
      ansible.builtin.user:
        name: james18
        shell: /bin/zsh
        groups: developers
        expires: 1422403387
    
  7. 移除帳號 james18 的過期時間。
    - name: Starting at Ansible 2.6, modify user, remove expiry time
      ansible.builtin.user:
        name: james18
        expires: -1
    
  8. 設定 ram19 密碼最長(過期要變更)使用天數。
    - name: Set maximum expiration date for password
      ansible.builtin.user:
        name: ram19
        password_expire_max: 10
    
  9. 設定 pushkar15 密碼最短(不能變更)使用天數。
    - name: Set minimum expiration date for password
      ansible.builtin.user:
        name: pushkar15
        password_expire_min: 5