summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/setup_test_user
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/setup_test_user')
-rw-r--r--test/integration/targets/setup_test_user/handlers/main.yml6
-rw-r--r--test/integration/targets/setup_test_user/tasks/default.yml14
-rw-r--r--test/integration/targets/setup_test_user/tasks/macosx.yml14
-rw-r--r--test/integration/targets/setup_test_user/tasks/main.yml37
4 files changed, 71 insertions, 0 deletions
diff --git a/test/integration/targets/setup_test_user/handlers/main.yml b/test/integration/targets/setup_test_user/handlers/main.yml
new file mode 100644
index 0000000..dec4bd7
--- /dev/null
+++ b/test/integration/targets/setup_test_user/handlers/main.yml
@@ -0,0 +1,6 @@
+- name: delete test user
+ user:
+ name: "{{ test_user_name }}"
+ state: absent
+ remove: yes
+ force: yes
diff --git a/test/integration/targets/setup_test_user/tasks/default.yml b/test/integration/targets/setup_test_user/tasks/default.yml
new file mode 100644
index 0000000..83ee8f1
--- /dev/null
+++ b/test/integration/targets/setup_test_user/tasks/default.yml
@@ -0,0 +1,14 @@
+- name: set variables
+ set_fact:
+ test_user_name: ansibletest0
+ test_user_group: null
+
+- name: set plaintext password
+ no_log: yes
+ set_fact:
+ test_user_plaintext_password: "{{ lookup('password', '/dev/null') }}"
+
+- name: set hashed password
+ no_log: yes
+ set_fact:
+ test_user_hashed_password: "{{ test_user_plaintext_password | password_hash('sha512') }}"
diff --git a/test/integration/targets/setup_test_user/tasks/macosx.yml b/test/integration/targets/setup_test_user/tasks/macosx.yml
new file mode 100644
index 0000000..d33ab04
--- /dev/null
+++ b/test/integration/targets/setup_test_user/tasks/macosx.yml
@@ -0,0 +1,14 @@
+- name: set variables
+ set_fact:
+ test_user_name: ansibletest0
+ test_user_group: staff
+
+- name: set plaintext password
+ no_log: yes
+ set_fact:
+ test_user_plaintext_password: "{{ lookup('password', '/dev/null') }}"
+
+- name: set hashed password
+ no_log: yes
+ set_fact:
+ test_user_hashed_password: "{{ test_user_plaintext_password }}"
diff --git a/test/integration/targets/setup_test_user/tasks/main.yml b/test/integration/targets/setup_test_user/tasks/main.yml
new file mode 100644
index 0000000..5adfb13
--- /dev/null
+++ b/test/integration/targets/setup_test_user/tasks/main.yml
@@ -0,0 +1,37 @@
+- name: gather distribution facts
+ gather_facts:
+ gather_subset: distribution
+ when: ansible_distribution is not defined
+
+- name: include distribution specific tasks
+ include_tasks: "{{ lookup('first_found', params) }}"
+ vars:
+ params:
+ files:
+ - "{{ ansible_distribution | lower }}.yml"
+ - default.yml
+ paths:
+ - tasks
+
+- name: create test user
+ user:
+ name: "{{ test_user_name }}"
+ group: "{{ test_user_group or omit }}"
+ password: "{{ test_user_hashed_password or omit }}"
+ register: test_user
+ notify:
+ - delete test user
+
+- name: run whoami as the test user
+ shell: whoami
+ vars:
+ # ansible_become_method and ansible_become_flags are not set, allowing them to be provided by inventory
+ ansible_become: yes
+ ansible_become_user: "{{ test_user_name }}"
+ ansible_become_password: "{{ test_user_plaintext_password }}"
+ register: whoami
+
+- name: verify becoming the test user worked
+ assert:
+ that:
+ - whoami.stdout == test_user_name