{"id":18363436,"url":"https://github.com/stuttgart-things/create-os-user","last_synced_at":"2026-05-17T08:33:38.850Z","repository":{"id":210013455,"uuid":"613339938","full_name":"stuttgart-things/create-os-user","owner":"stuttgart-things","description":"manage users and groups on linux systems","archived":false,"fork":false,"pushed_at":"2024-12-17T06:17:39.000Z","size":49,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-10T22:16:34.409Z","etag":null,"topics":["ansible","groups","linux","user-management","users"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stuttgart-things.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":"2023-03-13T11:36:53.000Z","updated_at":"2024-05-08T05:41:29.000Z","dependencies_parsed_at":"2023-11-30T10:24:42.530Z","dependency_job_id":"690f7a33-a0cd-49cc-b949-7d29f95addc2","html_url":"https://github.com/stuttgart-things/create-os-user","commit_stats":null,"previous_names":["stuttgart-things/create-os-user"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/stuttgart-things/create-os-user","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuttgart-things%2Fcreate-os-user","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuttgart-things%2Fcreate-os-user/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuttgart-things%2Fcreate-os-user/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuttgart-things%2Fcreate-os-user/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stuttgart-things","download_url":"https://codeload.github.com/stuttgart-things/create-os-user/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuttgart-things%2Fcreate-os-user/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33131947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T06:27:06.342Z","status":"ssl_error","status_checked_at":"2026-05-17T06:26:59.432Z","response_time":107,"last_error":"SSL_read: 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","groups","linux","user-management","users"],"created_at":"2024-11-05T23:06:30.577Z","updated_at":"2026-05-17T08:33:38.835Z","avatar_url":"https://github.com/stuttgart-things.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"stuttgart-things/create-os-user\n===============================\n\nmanage users and groups on linux systems.\n\n\u003cdetails\u003e\u003csummary\u003eVARIABLES\u003c/summary\u003e\n\nAdd a users variable containing the list of users to add. A good place to put\nthis is in `group_vars/all` or `group_vars/groupname` if you only want the\nusers to be on certain machines.\n\nThe following attributes are required for each user:\n\n* `username` - The user's username.\n* `name` - The full name of the user (gecos field).\n* `home` - The home directory of the user to create (optional, defaults to /home/username).\n* `uid` - The numeric user id for the user (optional). This is required for uid consistency\n  across systems.\n* `gid` - The numeric group id for the group (optional). Otherwise, the\n  `uid` will be used.\n* `password` - If a hash is provided then that will be used, but otherwise the\n  account will be locked.\n* `update_password` - This can be either 'always' or 'on_create'\n  - `'always'` will update passwords if they differ. (default)\n  - `'on_create'` will only set the password for newly created users.\n* `group` - Optional primary group override.\n* `groups` - A list of supplementary groups for the user.\n* `append` - If yes, will only add groups, not set them to just the list in groups (optional).\n* `profile` - A string block for setting custom shell profiles.\n* `ssh_key` - This should be a list of SSH keys for the user (optional). Each SSH key\n  should be included directly and should have no newlines.\n* `generate_ssh_key` - Whether to generate a SSH key for the user (optional, defaults to no).\n* `enable_ssh_tcp_forwarding` - Whether to set SSH-TCP Forwording or not\n \nIn addition, the following items are optional for each user:\n\n* `shell` - The user's shell. This defaults to /bin/bash. The default is\n  configurable using the users_default_shell variable if you want to give all\n  users the same shell, but it is different than /bin/bash.\n* `is_system_user` -  Set to `True` to create system user.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eDEFAULTS\u003c/summary\u003e\n\n* `users_create_per_user_group` (default: true) - when creating users, also\n  create a group with the same username and make that the user's primary\n  group.\n* `users_group` (default: users) - if users_create_per_user_group is _not_ set,\n  then this is the primary group for all created users.\n* `users_default_shell` (default: /bin/bash) - the default shell if none is\n  specified for the user.\n* `users_create_homedirs` (default: true) - create home directories for new\n  users. Set this to false if you manage home directories separately.\n* `deletion_user_group` (default: false) - delete group(s) and user(s). Set this to true to only\n  run delete tasks.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eROLE INSTALLATION\u003c/summary\u003e\n\ninstalls role and all of it's dependencies w/:\n\n```bash\ncat \u003c\u003cEOF \u003e /tmp/requirements.yaml\nroles:\n- src: https://github.com/stuttgart-things/create-os-user.git\n  scm: git\ncollections:\n- name: ansible.posix\nEOF\n\nansible-galaxy install -r /tmp/requirements.yaml --force\nansible-galaxy collection install -r /tmp/requirements.yaml --force\nrm -rf /tmp/requirements.yaml\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eEXAMPLE INVENTORY\u003c/summary\u003e\n\n```bash\ncat \u003c\u003cEOF \u003e inventory\n[appserver]\n1.2.3.4 ansible_user=sthings\nEOF\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eEXAMPLE PLAYBOOK - USERS DEFINITION INLINE\u003c/summary\u003e\n\nIncluding an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:\n\n```yaml\ncat \u003c\u003cEOF \u003e create-os-user.yaml\n- hosts: \"{{ target_host }}\"\n  gather_facts: true\n  become: true\n  roles:\n    - role: create-os-user\n      vars:\n        users:\n          - username: rke\n            name: rke user\n            groups: ['{{ admin_group }}', 'k8s-admins']\n            uid: 1005\n            home: /home/rke\n            profile: |\n              alias ll='ls -ahl'\n            generate_ssh_key: true\n            #ssh_key:\n            #  - \"{{ lookup('file', '~/.ssh/id_rsa.pub') }}\"\n            enable_ssh_tcp_forwarding: true\n\n        groups_to_create:\n          - name: k8s-admins\n            gid: 11000\n          - name: developers\n            gid: 21000\n\n        users_deleted:\n          - username: rke\n            uid: 1005\n            home: /home/rke/\n            remove: true\n            force: true\n\n        groups_deleted:\n          - name: developers\n            gid: 21000\nEOF\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eEXAMPLE PLAYBOOK - USERS DEFINITION VIA VARS FILE\u003c/summary\u003e\n\nYou can optionally choose to remove the user's home directory and mail spool with\n\n```yaml\ncat \u003c\u003cEOF \u003e users.yaml\n---\nusers:\n  - username: rke\n    name: rke user\n    groups: ['{{ admin_group }}', 'k8s-admins']\n    uid: 1005\n    home: /home/rke\n    profile: |\n      alias ll='ls -ahl'\n    generate_ssh_key: true\n    #ssh_key:\n    #  - \"{{ lookup('file', '/home/rke/.ssh/id_rsa.pub') }}\"\n    enable_ssh_tcp_forwarding: true\n  - username: test1\n    name: test1 user\n    groups: ['{{ admin_group }}', 'k8s-admins']\n    uid: 1006\n    home: /home/test1\n    profile: |\n      alias ll='ls -ahl'\n    generate_ssh_key: true\n    #ssh_key:\n    #  - \"{{ lookup('file', '/home/test1/.ssh/id_rsa.pub') }}\"\n    enable_ssh_tcp_forwarding: true\n  - username: test2\n    name: test2 user\n    groups: ['{{ admin_group }}', 'developers']\n    uid: 1007\n    home: /home/test2\n    profile: |\n      alias ll='ls -ahl'\n    generate_ssh_key: true\n    #ssh_key:\n    #  - \"{{ lookup('file', '/home/test2/.ssh/id_rsa.pub') }}\"\n    enable_ssh_tcp_forwarding: true\n\ngroups_to_create:\n  - name: k8s-admins\n    gid: 11000\n  - name: developers\n    gid: 21000\n\nusers_deleted:\n  - username: rke\n    uid: 1005\n    home: /home/rke/\n    remove: true\n    force: true\n  - username: test1\n    uid: 1006\n    home: /home/test1/\n    remove: true\n    force: true\n  - username: test2\n    uid: 1007\n    home: /home/test2/\n    remove: true\n    force: true\n\ngroups_deleted:\n  - name: k8s-admins\n    gid: 11000\n  - name: developers\n    gid: 21000\nEOF\n```\n\n```yaml\ncat \u003c\u003cEOF \u003e create-os-user.yaml\n---\n- hosts: \"{{ target_host }}\"\n  gather_facts: true\n  become: true\n  vars_files:\n    - users.yaml\n\n  roles:\n    - role: create-os-user\nEOF\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eEXAMPLE PLAYBOOK - COPY PUBLIC (SSH-)KEY TO AUTHORIZED_KEYS FILE\u003c/summary\u003e\n\n```yaml\ncat \u003c\u003cEOF \u003e users.yaml\n---\nusers:\n  - username: rke\n    name: rke user\n    groups: ['{{ admin_group }}', 'k8s-admins']\n    uid: 1005\n    home: /home/rke\n    profile: |\n      alias ll='ls -ahl'\n    generate_ssh_key: false # Default is true\n    ssh_key: # Commented in\n      - \"{{ lookup('file', '/home/rke/.ssh/id_rsa.pub') }}\"\n    enable_ssh_tcp_forwarding: true\n\ngroups_to_create:\n  - name: k8s-admins\n    gid: 11000\n  - name: developers\n    gid: 21000\nEOF\n```\n\n```yaml\ncat \u003c\u003cEOF \u003e create-os-user.yaml\n---\n- hosts: \"{{ target_host }}\"\n  gather_facts: true\n  become: true\n  vars_files:\n    - users.yaml\n\n  roles:\n    - role: create-os-user\nEOF\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eEXAMPLE CONFIG - REMOVE USERS\u003c/summary\u003e\n\n```yaml\ncat \u003c\u003cEOF \u003e users.yaml\n---\nusers_deleted:\n  - username: rke\n    uid: 1005\n    home: /home/rke/\n    remove: true\n    force: true\n\ngroups_deleted:\n  - name: k8s-admins\n    gid: 11000\n  - name: developers\n    gid: 21000\nEOF\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eEXAMPLE GENERATING HASHED PASSWORD\u003c/summary\u003e\n\n```bash\nansible all -i localhost, -m debug -a \"msg={{ 'password' | password_hash('sha512', 'mysecretsalt') }}\"\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eEXAMPLE EXECUTION\u003c/summary\u003e\n\n```bash\n# Command to create group(s) and user(s)\nansible-playbook -i inventory create-os-user.yaml -vv\n\n# Command to delete group(s) and user(s)\nansible-playbook -i inventory create-os-user.yaml -vv --extra-vars \"deletion_user_group=true\"\n```\n\n\u003c/details\u003e\n\n## License\n\u003cdetails\u003e\u003csummary\u003eLICENSE\u003c/summary\u003e\n\nCopyright 2020 patrick hermann.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\u003c/details\u003e\n\nRole history\n----------------\n| date  | who | changelog |\n|---|---|---|\n|2024-04-22   | Andre Ebert | Added linting and task to prompt for user password and to delete user directories \n|2020-10-10   | Patrick Hermann | Updated for using of ansible collections, fixed role structure, default 'admin-user group' for debian/redhat\n|2020-04-20   | Patrick Hermann | intial commit for creation of users/groups w/ ansible\n\nAuthor Information\n------------------\n\n```yaml\nAndre Ebert, 04/2024, andre.ebert@sva.de, Stuttgart-Things\nPatrick Hermann, 03/2020, patrick.hermann@sva.de, Stuttgart-Things\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstuttgart-things%2Fcreate-os-user","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstuttgart-things%2Fcreate-os-user","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstuttgart-things%2Fcreate-os-user/lists"}