# # https://www.howtouselinux.com/post/create-user-with-ansible # https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html # https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html # --- - name: "14 - custom ansible - verifyl user" hosts: dev become: yes # Run tasks with root/sudo privileges vars: username: testuser1 tasks: - name: check if user exists ansible.builtin.command: id {{ username }} # ansible.builtin.shell: id {{ username }} register: user_check ignore_errors: true - name: display user information ansible.builtin.debug: msg: user '{{ username }}' exists ! when: user_check.rc == 0 - name: display error message if user does not exist ansible.builtin.debug: msg: user '{{ username }}' does not exist ! when: user_check.rc != 0