main.yml (1247B)
1 - name: gather distribution facts 2 gather_facts: 3 gather_subset: distribution 4 when: ansible_distribution is not defined 5 6 - name: include distribution specific tasks 7 include_tasks: "{{ lookup('first_found', params) }}" 8 vars: 9 params: 10 files: 11 - "{{ ansible_distribution | lower }}.yml" 12 - default.yml 13 paths: 14 - tasks 15 16 - set_fact: 17 delete_users: "{{ (delete_users | default([])) + [test_user_name] }}" 18 19 - name: create test user 20 user: 21 name: "{{ test_user_name }}" 22 group: "{{ test_user_group or omit }}" 23 groups: "{{ test_user_groups or omit }}" 24 password: "{{ test_user_hashed_password or omit }}" 25 register: test_user 26 notify: 27 - delete test user 28 29 - name: maybe configure sudo 30 include_tasks: sudo_config.yml 31 when: test_user_allow_sudo != False 32 33 - name: run whoami as the test user 34 shell: whoami 35 vars: 36 # ansible_become_method and ansible_become_flags are not set, allowing them to be provided by inventory 37 ansible_become: yes 38 ansible_become_user: "{{ test_user_name }}" 39 ansible_become_password: "{{ test_user_plaintext_password }}" 40 register: whoami 41 42 - name: verify becoming the test user worked 43 assert: 44 that: 45 - whoami.stdout == test_user_name