{"id":15774837,"url":"https://github.com/jtyr/ansible-users","last_synced_at":"2026-05-07T11:33:51.787Z","repository":{"id":69603763,"uuid":"131068041","full_name":"jtyr/ansible-users","owner":"jtyr","description":"Ansible role to create and manage Linux users, groups and SSH keys.","archived":false,"fork":false,"pushed_at":"2019-09-24T10:20:04.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-06T19:53:41.794Z","etag":null,"topics":["ansible","ansible-roles","ssh-key","user-management"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jtyr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-25T21:56:28.000Z","updated_at":"2020-01-19T17:20:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"8f9ae07c-38e3-4a62-b6c4-eff143fd9540","html_url":"https://github.com/jtyr/ansible-users","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/jtyr/ansible-users","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtyr%2Fansible-users","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtyr%2Fansible-users/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtyr%2Fansible-users/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtyr%2Fansible-users/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jtyr","download_url":"https://codeload.github.com/jtyr/ansible-users/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtyr%2Fansible-users/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32735206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-roles","ssh-key","user-management"],"created_at":"2024-10-04T16:40:53.190Z","updated_at":"2026-05-07T11:33:51.769Z","avatar_url":"https://github.com/jtyr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"users\n=====\n\nAnsible role which helps to create and manage Linux users, groups and SSH keys.\n\nThe configuration of the role is done in such way that it should not be\nnecessary to change the role for any kind of configuration. All can be\ndone either by changing role parameters or by declaring completely new\nconfiguration as a variable. That makes this role absolutely\nuniversal. See the examples below for more details.\n\nPlease report any issues or send PR.\n\n\nExamples\n--------\n\n```yaml\n---\n\n- name: Example of how to create a group\n  hosts: all\n  vars:\n    users:\n      - group: testgroup\n  roles:\n    - users\n\n- name: Example of how to remove a group\n  hosts: all\n  vars:\n    users:\n      - group: testgroup\n        group_state: absent\n  roles:\n    - users\n\n- name: Example of how to create a user\n  hosts: all\n  vars:\n    users:\n      - name: myuser\n  roles:\n    - users\n\n- name: Example of how to remove a user\n  hosts: all\n  vars:\n    users:\n      - name: myuser\n        state: absent\n  roles:\n    - users\n\n- name: Example of how to create a user with a specific UID, group and GID, comment, password and SSH authorized and private key\n  hosts: all\n  vars:\n    users:\n      - name: myuser\n        uid: 2000\n        group: myusers\n        gid: 2000\n        comment: My user\n        password: \"$6$DaWdfn9ZmxeMMMe/$3snNH112PneNfs81JGCD4p5f10b7gnNgF8wk.2HPp0ZzWrxrPnH66YE4PDN.WP11X618U47eEX2Mr2cSv4ec61\"\n        ssh_auth_keys:\n          - ssh-rsa AAAAB3NzaC1yc2EAAAEDAQABAAABAQCWp73FFB8Ck/S6i3lTijbfQGxnHC84iu7anCfSeyJE89JuI9C2OU+QlW6tsl/SbXY2LR0TGUhD5aX2ZvC3CZrrl4Yq4/9upEVgUpzJdDJo6ZcLOWVDuetHArNbIC2pcdU/skDoCP0wcuBJ09qLZ4qi5q/r6RS79PmzhvNg6CjzmT5wztMZIjlS4Z7+RqeR1WZMur8FXRfy25jqewdUUWIDVxOvRJLvwB1tW9NA9oe7jp4E9FAn4ZgsMs/143N8bw16M5g7c6nOMvQUBRld10ZnO10QTMpE3WWKiHgyCeQCdZ8W4EsrIUelbOoLkFuMADoZ9gO9biJ/2aKIqr9n+++d ansible@host\n        ssh_priv_keys:\n          - key: |\n              -----BEGIN RSA PRIVATE KEY-----\n              ...\n              -----END RSA PRIVATE KEY-----\n            # Optionally you can also specify the file, owner, group and mode of each priv key\n  roles:\n    - users\n\n- name: Example of how to create a SFTP user\n  hosts: all\n  vars:\n    users:\n      - name: myuser\n        group: sftp\n        home: /sftp/myuser\n        # The user doesn't need shell\n        shell: /bin/false\n        # Explicite list of allowed public SSH keys\n        ssh_auth_keys:\n          - ssh-rsa AAAAB3NzaC1yc2EAAAEDAQABAAABAQCWp73FFB8Ck/S6i3lTijbfQGxnHC84iu7anCfSeyJE89JuI9C2OU+QlW6tsl/SbXY2LR0TGUhD5aX2ZvC3CZrrl4Yq4/9upEVgUpzJdDJo6ZcLOWVDuetHArNbIC2pcdU/skDoCP0wcuBJ09qLZ4qi5q/r6RS79PmzhvNg6CjzmT5wztMZIjlS4Z7+RqeR1WZMur8FXRfy25jqewdUUWIDVxOvRJLvwB1tW9NA9oe7jp4E9FAn4ZgsMs/143N8bw16M5g7c6nOMvQUBRld10ZnO10QTMpE3WWKiHgyCeQCdZ8W4EsrIUelbOoLkFuMADoZ9gO9biJ/2aKIqr9n+++d ansible@host\n        # The home directory is writable only by root\n        # (user cannot create any files or directories there)\n        home_mode: \"0755\"\n        home_owner: root\n        home_group: root\n        # The ~/.ssh directory is also writable only by root (user cannot delete it),\n        # but sftp group can read from it\n        ssh_dir_mode: \"0710\"\n        ssh_dir_owner: root\n        ssh_dir_group: sftp\n        # The authorized_keys file is readable by the sftp group\n        # (user cannot edit it)\n        ssh_auth_mode: \"0640\"\n        ssh_auth_owner: root\n        ssh_auth_group: sftp\n        # We can restrict the home directory creation to a specific host\n        # (usefull when the home directory is created on a shared storage)\n        host: gluster-centos7a\n        # Create ~/data directory which is writable by the sftp group\n        # (owned by root to prevent its deletion by the user)\n        add_dirs:\n          - name: data\n            owner: root\n            group: sftp\n            mode: \"0770\"\n  roles:\n    - users\n\n- name: Example of a more complex user management\n  hosts: all\n  vars:\n    # Salt for always the same password hash\n    users_password_salt: mysecretsalt\n\n    # To facilitate simple password change\n    users_root_password: \"{{ 'ro0t123' | password_hash('sha512', users_password_salt) }}\"\n    users_ansible_password: \"{{ 'ans1bl3' | password_hash('sha512', users_password_salt) }}\"\n\n    # Default list of users\n    users__default:\n      # Set root password\n      - name: root\n        password: \"{{ users_root_password }}\"\n      # Create ansible user and group\n      - name: ansible\n        uid: 1000\n        group: ansible\n        gid: 1000\n        comment: Configuration management user\n        password: \"{{ users_ansible_password }}\"\n        # Add single SSH public key\n        ssh_auth_keys:\n          - ssh-rsa AAAAB3NzaC1yc2EAAAEDAQABAAABAQCWp73FFB8Ck/S6i3lTijbfQGxnHC84iu7anCfSeyJE89JuI9C2OU+QlW6tsl/SbXY2LR0TGUhD5aX2ZvC3CZrrl4Yq4/9upEVgUpzJdDJo6ZcLOWVDuetHArNbIC2pcdU/skDoCP0wcuBJ09qLZ4qi5q/r6RS79PmzhvNg6CjzmT5wztMZIjlS4Z7+RqeR1WZMur8FXRfy25jqewdUUWIDVxOvRJLvwB1tW9NA9oe7jp4E9FAn4ZgsMs/143N8bw16M5g7c6nOMvQUBRld10ZnO10QTMpE3WWKiHgyCeQCdZ8W4EsrIUelbOoLkFuMADoZ9gO9biJ/2aKIqr9n+++d ansible@host\n\n    # Custom list of users\n    users__custom:\n      # Existing remote user (e.g. from LDAP)\n      - remote: yes\n        name: service1\n        # Add multiple SSH public keys\n        ssh_auth_keys:\n          - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAEABAQCWp73FFB8Ck/S6i6lTjibfQGxnHC84iu7anCfSeyJE89JuI9C2OU+QlWatsl/SbXY2LR0TGUhD5aX2ZvC3CZrrl4Yq4/fy25jqewdUUWIDVxOvRJLvwB1tW9NA9oe7jp9upEVgUpzJdDJo6ZcLOWVDuetHArNbIC2pcdU/skcoCP0wcuBJ09qLZ4qi5q/r6RS79PmzhvNg6CjzmT5wztMZIjlS4Z7+RqeR8WZMur8FXR4E9FAn4ZgsMs/143N8bw16M5g7c6nOMvQUBRld10ZnO10QtMpE3WWKiHgyCeQCdZ8W4EsrIUelbOoLkFuMADoZ9gO9biJ/2aKIqr9n+++d ansible@host1\n          - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABACABAQCWp73FFB8Ck//skcoEP0wcuBJ09qLZ4qi5q/r6RS79PmzhvNg6CjzmT5wzt3ZIjlS4Z7+RqeR8WZMur8FXRfy25jqewdUUWIDVxOvRJLvwB1tW9NA9oe7jp4E9FAn4ZgsMs/143N8bw16M5g7c6nOMvQUBRld10ZnO10QTMpE3WWKiHgyCeQCdZ8W4EsrIUelbOoLkFuMADoZ9gO9biJS6i6lTijbfQGxnHC84iu7anCfSeyJE89JuI9C2OU+QlW6tsl/SbXY2LR0TGUhD5aX2ZvC3CZrll4Yq4/9upEVgUpzJdDJo6ZcLOWVDuetHArNbIC2pcdU/2aKIqr9n+++d ansible@host2\n      # Remove previously created user\n      - name: johndoe\n        comment: John Doe\n        group: users\n        state: absent\n        password: \"{{ users_ansible_password }}\"\n\n    # Final list of users\n    users: \"{{\n      users__default +\n      users__custom }}\"\n  roles:\n    - users\n```\n\n\nRole variables\n--------------\n\n```yaml\n# Whether to remove the user's home directory when the `state` set to `absent`\nusers_remove: yes\n\n# Add SSH keys exclusively (remove all unknown keys)\nusers_ssh_auth_keys_exclusive: yes\n\n# Force to show log even if it contains sensitive information (e.g. SSH priv key)\nusers_force_show_log: no\n\n# List of users/groups to be created (see README for examples)\nusers: []\n```\n\n\nLicense\n-------\n\nMIT\n\n\nAuthor\n------\n\nJiri Tyr\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjtyr%2Fansible-users","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjtyr%2Fansible-users","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjtyr%2Fansible-users/lists"}