summaryrefslogtreecommitdiff
path: root/ansible-practice/system/14-playbook-verify-user.yml
diff options
context:
space:
mode:
Diffstat (limited to 'ansible-practice/system/14-playbook-verify-user.yml')
-rw-r--r--ansible-practice/system/14-playbook-verify-user.yml31
1 files changed, 31 insertions, 0 deletions
diff --git a/ansible-practice/system/14-playbook-verify-user.yml b/ansible-practice/system/14-playbook-verify-user.yml
new file mode 100644
index 0000000..f617843
--- /dev/null
+++ b/ansible-practice/system/14-playbook-verify-user.yml
@@ -0,0 +1,31 @@
+#
+# 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 - verify 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
+ tags: ['user_exists']
+
+ - name: display error message if user does not exist
+ ansible.builtin.debug:
+ msg: user '{{ username }}' does not exist !
+ when: user_check.rc != 0
+ tags: ['user_does_not_exist']
+