模組文件

  1. 查詢 user 模組文件。
    [deyu1@kvm19 ansible]$ ansible-doc user
    
  2. 查詢 user 模組文件的範例,新增帳號 johnd,且指定群組及 uid。
    [deyu1@kvm19 ansible]$ ansible-doc file | grep ^EX -A8
    EXAMPLES:
    
    - name: Add the user 'johnd' with a specific uid and a primary group of 'admin'
      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' an>
      user:
        name: james
        shell: /bin/bash
        groups: admins,developers
        append: yes
    
  4. 刪除帳號 johnd。
    - name: Remove the user 'johnd'
      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
      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
      user:
        name: james18
        shell: /bin/zsh
        groups: developers
        expires: 1422403387
    
  7. 移除帳號 james18 的過期時間。
    - name: Starting at Ansible 2.6, modify user, remove expiry time
      user:
        name: james18
        expires: -1