summaryrefslogtreecommitdiff
path: root/ansible-practice/system/14-playbook-verify-user.yml
diff options
context:
space:
mode:
authorboom2 <blizzack@blizzack.com>2023-12-21 15:49:16 -0500
committerboom2 <blizzack@blizzack.com>2023-12-21 15:49:16 -0500
commit200680e7c8cbd6b4426c3ce232568b1e06446bde (patch)
treeb122f103cc4dce8cea078c20dac107612399640e /ansible-practice/system/14-playbook-verify-user.yml
parenta21b2f4bb64bd0f633d8a6a15f27a73103df70c0 (diff)
- renamed playbook to follow convention
-- add /etc/rc.d/rc.M in 'fetch file playbook' for future clamav playbook
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']
+