Debian Codegraph @

ansible_collections/community/crypto/tests/integration/targets/luks_device/tasks/main.yml

raw
1 ---
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 ####################################################################
7 # WARNING: These are designed specifically for Ansible tests #
8 # and should not be used as examples of how to write Ansible roles #
9 ####################################################################
10
11 - name: Copy keyfiles
12 ansible.builtin.copy:
13 src: '{{ item }}'
14 dest: '{{ remote_tmp_dir }}/{{ item }}'
15 loop:
16 - keyfile1
17 - keyfile2
18
19 - name: Include OS-specific variables
20 ansible.builtin.include_vars: '{{ lookup("first_found", search) }}'
21 vars:
22 search:
23 files:
24 - '{{ ansible_facts.distribution | lower }}-{{ ansible_facts.distribution_major_version }}.yml'
25 - '{{ ansible_facts.distribution | lower }}-{{ ansible_facts.distribution_version }}.yml'
26 - '{{ ansible_facts.distribution | lower }}.yml'
27 - '{{ ansible_facts.os_family | lower }}.yml'
28 - default.yml
29 paths:
30 - vars
31
32 - name: Make sure cryptsetup is installed
33 ansible.builtin.package:
34 name: '{{ cryptsetup_package }}'
35 state: present
36 become: true
37
38 - name: Install additionally required packages
39 ansible.builtin.package:
40 name: '{{ luks_extra_packages }}'
41 state: present
42 become: true
43 when: luks_extra_packages | length > 0
44
45 - name: Determine cryptsetup version
46 ansible.builtin.command: cryptsetup --version
47 register: cryptsetup_version
48
49 - name: Extract cryptsetup version
50 ansible.builtin.set_fact:
51 cryptsetup_version: >-
52 {{ cryptsetup_version.stdout_lines[0] | regex_search('cryptsetup ([0-9]+\.[0-9]+\.[0-9]+)') | split | last }}
53
54 - name: Create cryptfile
55 ansible.builtin.command: dd if=/dev/zero of={{ remote_tmp_dir.replace('~', ansible_facts.env.HOME) }}/cryptfile bs=1M count=32
56
57 - name: Figure out next loopback device
58 ansible.builtin.command: losetup -f
59 become: true
60 register: cryptfile_device_output
61
62 - name: Create lookback device
63 ansible.builtin.command: losetup -f {{ remote_tmp_dir.replace('~', ansible_facts.env.HOME) }}/cryptfile
64 become: true
65
66 - name: Store some common data for tests
67 ansible.builtin.set_fact:
68 cryptfile_device: "{{ cryptfile_device_output.stdout_lines[0] }}"
69 cryptfile_passphrase1: "uNiJ9vKG2mUOEWDiQVuBHJlfMHE"
70 cryptfile_passphrase2: "HW4Ak2HtE2vvne0qjJMPTtmbV4M"
71 cryptfile_passphrase3: "qQJqsjabO9pItV792k90VvX84MM"
72
73 - block:
74 - ansible.builtin.include_tasks: run-test.yml
75 with_fileglob:
76 - "tests/*.yml"
77
78 always:
79 - name: Make sure LUKS device is gone
80 community.crypto.luks_device:
81 device: "{{ cryptfile_device }}"
82 state: absent
83 become: true
84 ignore_errors: true
85
86 - ansible.builtin.command: losetup -d "{{ cryptfile_device }}"
87 become: true
88
89 - ansible.builtin.file:
90 dest: "{{ remote_tmp_dir.replace('~', ansible_facts.env.HOME) }}/cryptfile"
91 state: absent