Debian Codegraph @

ansible_collections/community/crypto/tests/integration/targets/setup_openssl/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: Register system environment
12 ansible.builtin.command: "{{ ansible_facts.python.executable }} -c 'import os; print(dict(os.environ))'"
13 register: sys_environment
14
15 - name: Show system environment
16 ansible.builtin.debug:
17 var: sys_environment.stdout_lines
18
19 - name: Default value for OpenSSL binary path
20 ansible.builtin.set_fact:
21 openssl_binary: openssl
22
23 - name: Include OS-specific variables
24 ansible.builtin.include_vars: '{{ ansible_facts.os_family }}.yml'
25 when: not ansible_facts.os_family == "Darwin"
26
27 - name: Check whether OpenSSL is there
28 ansible.builtin.command: "{{ openssl_binary }} version"
29 register: openssl_version_full
30 ignore_errors: true
31
32 - name: Install OpenSSL
33 become: true
34 ansible.builtin.package:
35 name: '{{ openssl_package_name }}'
36 when: not ansible_facts.os_family == 'Darwin' and openssl_version_full is failed
37
38 - name: Register openssl version (full)
39 ansible.builtin.command: "{{ openssl_binary }} version"
40 register: openssl_version_full
41
42 - name: Show openssl version (full)
43 ansible.builtin.debug:
44 var: openssl_version_full.stdout_lines
45
46 - when: ansible_facts.os_family == "Darwin" and "LibreSSL" in openssl_version_full.stdout
47 # In case LibreSSL is installed on macOS, we need to install a more modern OpenSSL
48 block:
49 - name: MACOS | Find brew binary
50 ansible.builtin.command: which brew
51 register: brew_which
52
53 - name: MACOS | Get owner of brew binary
54 ansible.builtin.stat:
55 path: "{{ brew_which.stdout }}"
56 register: brew_stat
57
58 - name: MACOS | Install openssl
59 community.general.homebrew:
60 name: openssl
61 state: present
62 become: true
63 become_user: "{{ brew_stat.stat.pw_name }}"
64
65 - name: MACOS | Locale openssl binary
66 ansible.builtin.command: brew --prefix openssl
67 become: true
68 become_user: "{{ brew_stat.stat.pw_name }}"
69 register: brew_openssl_prefix
70
71 - name: MACOS | Point to OpenSSL binary
72 ansible.builtin.set_fact:
73 openssl_binary: "{{ brew_openssl_prefix.stdout }}/bin/openssl"
74
75 - name: MACOS | Register openssl version (full)
76 ansible.builtin.command: "{{ openssl_binary }} version"
77 register: openssl_version_full_again
78 # We must use a different variable to prevent the 'when' condition of the surrounding block to fail
79
80 - name: MACOS | Show openssl version (full)
81 ansible.builtin.debug:
82 var: openssl_version_full_again.stdout_lines
83
84 - name: Register openssl version
85 ansible.builtin.shell: "{{ openssl_binary }} version | cut -d' ' -f2"
86 register: openssl_version
87
88 - name: Make openssl version a string
89 ansible.builtin.set_fact:
90 openssl_version: "{{ openssl_version.stdout }}"
91
92 - when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
93 block:
94
95 - name: Install from system packages
96 when: ansible_facts.os_family != "Darwin" and target_system_python
97 block:
98
99 - name: Install cryptography (Python 3 from system packages)
100 become: true
101 ansible.builtin.package:
102 name: '{{ cryptography_package_name_python3 }}'
103 when: ansible_facts.python_version is version('3.0', '>=')
104
105 - name: Install cryptography (Python 2 from system packages)
106 become: true
107 ansible.builtin.package:
108 name: '{{ cryptography_package_name }}'
109 when: ansible_facts.python_version is version('3.0', '<')
110
111 - name: Install from PyPi
112 when: ansible_facts.os_family == "Darwin" or not target_system_python
113 block:
114
115 - name: Install cryptography (PyPi)
116 become: true
117 ansible.builtin.pip:
118 name: 'cryptography{% if ansible_facts.os_family == "Darwin" %}>=3.3{% endif %}'
119 state: "{{ 'latest' if not target_system_python_cannot_upgrade_cryptography else omit }}"
120 extra_args: "-c {{ remote_constraints }}"
121
122 - name: Obtain cryptography information
123 community.crypto.crypto_info:
124 register: crypto_info
125
126 - name: Register cryptography version
127 ansible.builtin.set_fact:
128 cryptography_version: "{{ crypto_info.python_cryptography_capabilities.version }}"
129
130 - name: Print default key sizes
131 ansible.builtin.debug:
132 msg: "Default RSA key size: {{ default_rsa_key_size }} (for certificates: {{ default_rsa_key_size_certificates }})"