Debian Codegraph @

ansible_collections/community/sops/docs/docsite/rst/guide.rst

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 .. _ansible_collections.community.sops.docsite.guide:
7
8 Protecting Ansible secrets with SOPS
9 ====================================
10
11 `CNCF SOPS <https://github.com/getsops/sops>`_ allows to encrypt and decrypt files using various key sources (GPG, AWS KMS, GCP KMS, ...). For structured data, such as YAML, JSON, INI and ENV files, it will encrypt values, but not mapping keys. For YAML files, it also encrypts comments. This makes it a great tool for encrypting credentials with Ansible: you can easily see which files contain which variable, but the variables themselves are encrypted.
12
13 The ability to utilize various keysources makes it easier to use in complex environments than :ref:`Ansible Vault <vault_guide_index>`.
14
15 .. contents::
16 :local:
17 :depth: 1
18
19 Installing SOPS
20 ---------------
21
22 You can find binaries and packages `on the project's release page <https://github.com/getsops/sops/releases>`_. Depending on your operating system, you might also be able to install it with your system's package manager.
23
24 This collection provides a :ansplugin:`role community.sops.install <community.sops.install#role>` which allows to install SOPS and `GNU Privacy Guard (GPG) <https://en.wikipedia.org/wiki/GNU_Privacy_Guard>`__. The role allows to install SOPS from the system's package manager or from GitHub; see :ansopt:`community.sops.install#role:main:sops_source` for details. Both SOPS and GPG can be installed on the remote hosts or the Ansible controller; see :ansopt:`community.sops.install#role:main:sops_install_on_localhost` for details.
25
26 .. code-block:: yaml
27
28 - name: Playbook to install SOPS
29 hosts: all
30 tasks:
31 # To use the sops_encrypt module on a remote host, you need to install SOPS on it:
32 - name: Install SOPS on remote hosts
33 ansible.builtin.include_role:
34 name: community.sops.install
35 vars:
36 sops_version: 2.7.0 # per default installs the latest version
37
38 # To use the lookup plugin, filter plugin, vars plugin, or the load_vars action,
39 # you need SOPS installed on localhost:
40 - name: Install SOPS on localhost
41 ansible.builtin.include_role:
42 name: community.sops.install
43 vars:
44 sops_install_on_localhost: true
45
46 When using ansible-core 2.11 or later, you can also use two convenience playbooks:
47
48 .. code-block:: console
49
50 # Install SOPS on Ansible controller
51 $ ansible-playbook community.sops.install_localhost
52
53 # Install SOPS on remote servers
54 $ ansible-playbook community.sops.install --inventory /path/to/inventory
55
56 Installing community.sops in an Execution Environment
57 -----------------------------------------------------
58
59 When building an execution environment containing community.sops, please note that by default SOPS is not automatically installed. This is due to a limitation of the dependency specification system for execution environments. If you are building an execution environment that contains community.sops, you should make sure that SOPS is installed in it.
60
61 The simplest way of ensuring this is to use the ``community.sops.install_localhost`` playbook. When defining an execution environment, you can add a ``RUN`` additional build step to your ``execution-environment.yml``:
62
63 .. code-block:: yaml
64
65 ---
66 version: 3
67 dependencies:
68 galaxy: requirements.yml
69 additional_build_steps:
70 append_final:
71 # Ensure that SOPS is installed in the EE, assuming the EE is for ansible-core 2.11 or newer
72 - RUN ansible-playbook -v community.sops.install_localhost
73
74 Note that this only works if the execution environment is built with ansible-core 2.11 or newer. When using an execution environment with Ansible 2.9, you have to use the :ansplugin:`community.sops.install#role` role manually. Also note that you need to make sure that Ansible 2.9 uses the correct Python interpreter to be able to install system packages with; in the below example we are assuming a RHEL/CentOS based execution environment base image:
75
76 .. code-block:: yaml
77
78 ---
79 version: 3
80 dependencies:
81 galaxy: requirements.yml
82 additional_build_steps:
83 append_final:
84 # Special step needed for Ansible 2.9 based EEs
85 - >-
86 RUN ansible localhost -m include_role -a name=community.sops.install
87 -e sops_install_on_localhost=true
88 -e ansible_python_interpreter=/usr/libexec/platform-python
89
90 Once this step has been taken care of, you can use all plugins and modules (on ``localhost``) from community.sops in the execution environment.
91
92 Setting up SOPS
93 ---------------
94
95 From now on this guide assumes that you have installed SOPS.
96
97 For simplicity, you can work with GPG keys. If you do not have one, or do not want to use yours, you can run ``gpg --quick-generate-key [email protected]`` to create a GPG key for the user ID ``[email protected]``. You will need its 40 hex-digit key ID that is printed at the end. The first step is to create a ``.sops.yaml`` file in the directory tree you are working in:
98
99 .. code-block:: yaml
100
101 creation_rules:
102 - pgp: 'FBC7B9E2A4F9289AC0C1D4843D16CEE4A27381B4'
103
104 Here, ``FBC7B9E2A4F9289AC0C1D4843D16CEE4A27381B4`` is the 40 hex-digit key ID. With this file you can create a SOPS-encrypted file by running the following in the directory where ``.sops.yaml`` was placed, or a subdirectory of it:
105
106 .. code-block:: console
107
108 $ sops test.sops.yaml
109
110 This will open an editor window with an example YAML file. Put the following content in:
111
112 .. code-block:: yaml
113
114 # This is a comment
115 hello: world
116 foo:
117 - bar
118 - baz
119
120 After closing the editor, SOPS will create ``test.sops.yaml`` with the encrypted contents:
121
122 .. code-block:: yaml
123
124 #ENC[AES256_GCM,data:r6Ok05DzzHBO4tonlz2t49CF,iv:Y0P39iXwaGYU9NG5oRC3NuaGVL40uruSze0CxbDTpTk=,tag:EzoG+X+BJAHbxE0asSyGlQ==,type:comment]
125 hello: ENC[AES256_GCM,data:onBZqWk=,iv:bwj4bwaeh3vpVDYqY2AnYo1thF955i5vbFpCC1DwJtM=,tag:4qbVzuHTaPrXm64r2Rqz1Q==,type:str]
126 foo:
127 - ENC[AES256_GCM,data:UsY8,iv:USv71rKfvbTF+3a5T2WO56wGVu609/0uigqkO0pa6U4=,tag:s8NdqLp+8OOQg4xDfE78oA==,type:str]
128 - ENC[AES256_GCM,data:Dhmo,iv:qWs5gN2SCXYq0EfGelZhODsdViKB9w2taQMhsqy0D2g=,tag:I+ZFvuxnsvQmywqz+a/M9w==,type:str]
129 sops:
130 kms: []
131 gcp_kms: []
132 azure_kv: []
133 hc_vault: []
134 age: []
135 lastmodified: "2021-06-15T19:36:34Z"
136 mac: ENC[AES256_GCM,data:HAvLeOvt7xWI7B5TCeDEsL6sOSzGGeTbgBSJaZkwadmoAm3Ny4IZPF8JAbFaPPLmN8FJVAt4D61aIWa6Xwi3xMj1g6DmxFfgK6JFJqWqW122UlMhqZ/WuMWFV6yVxpTLDXgemndgGDJqUTUi14FMh/MzPDg4f6kFP64kA9fpLrY=,iv:LdhswnMymZG8J9na/jnF3WYnX0DvzvoBlvjUCu4nI6c=,tag:Qt4d7L3FXsgfmg9iOs8P4A==,type:str]
137 pgp:
138 - created_at: "2021-06-15T19:36:01Z"
139 enc: |-
140 -----BEGIN PGP MESSAGE-----
141
142 wcBMAyUpShfNkFB/AQgAT8OAKnWLBQRG3kT5lZCmyoPzK6RwF0zRkwCzJkLNl6xg
143 nQjUjpD03ZD4FtiRidspXEj7NvCLDghJ0UETtDjmrwsTeJ5YAK/JxouWmoNhVVdF
144 p0qOlj/THXIV+ypVaqrisZGZiTqeWjUNFuayknvjm3XduOOPZA1MIJ14pQxcgca4
145 NWmKwPwXTWEy3RJ0ZsnjjjYvKHjHyvbHdbDgARu8R1jEgdNPKPBRVpEY6RNeafXI
146 gFBVRfrhPKD6HmnmNvjHwUc/K+wOa1ciIYVrT4mPXoyBsFkyV0egh/QRf0JO8+X7
147 Ut/jEtCrl9BXJCNYGmC5EU3PPiFlAu1MRxlCiPNWltLmASn2w62wMpgih6f+OpI/
148 zyEOdz0qx80LEfhv3+jBbDfBwz4GqpAHUr0fCXDzeDiKfzlU6isagoIAhJfwX6oG
149 NeQ47ktk1XhPmgIwxxuvonG14iQoU2cA
150 =GoXQ
151 -----END PGP MESSAGE-----
152 fp: FBC7B9E2A4F9289AC0C1D4843D16CEE4A27381B4
153 unencrypted_suffix: _unencrypted
154 version: 3.7.1
155
156 The first line contains the encrypted content. The second line contains the unencrypted key of ``hello: world``, and the encrypted string value ``world``. The next few lines contain the unencrypted key ``foo`` with the encrypted list elements.
157
158 At the end, the ``sops`` section contains metadata, which includes the private key needed to decrypt the file encrypted with the public key of the GPG key ID ``FBC7B9E2A4F9289AC0C1D4843D16CEE4A27381B4``. If you had multiple GPG keys configured, or also other key sources, you can also find the file secret key encrypted with these keys here.
159
160 Working with encrypted files
161 ----------------------------
162
163 You can decrypt SOPS-encrypted files with the :ansplugin:`community.sops.sops lookup plugin <community.sops.sops#lookup>`, and dynamically encrypt data with the :ansplugin:`community.sops.sops_encrypt module <community.sops.sops_encrypt#module>`. Being able to encrypt is useful when you create or update secrets in your Ansible playbooks.
164
165 Assume that you have an encrypted private key ``keys/private_key.pem.sops``, which was in PEM format before being encrypted by SOPS:
166
167 .. code-block:: console
168
169 $ openssl genrsa -out keys/private_key.pem 2048
170 $ sops --encrypt keys/private_key.pem > keys/private_key.pem.sops
171 $ wipe keys/private_key.pem
172
173 To use it in a playbook, for example to pass it to the :ansplugin:`community.crypto.openssl_csr module <community.crypto.openssl_csr#module>` to create a certificate signing request (CSR), you can use the :ansplugin:`community.sops.sops lookup plugin <community.sops.sops#lookup>` to load it:
174
175 .. code-block:: yaml+jinja
176
177 ---
178 - name: Load SOPS-encrypted private key
179 hosts: localhost
180 gather_facts: false
181 tasks:
182 - name: Create CSR with encrypted private key
183 community.crypto.openssl_csr:
184 # The private key is provided with SOPS:
185 privatekey_content: "{{ lookup('community.sops.sops', 'keys/private_key.pem.sops') }}"
186 # Store the CSR on disk unencrypted:
187 path: ansible.com.csr
188 # This is going to be a CSR for ansible.com and www.ansible.com
189 subject_alt_name:
190 - DNS:ansible.com
191 - DNS:www.ansible.com
192 use_common_name_for_san: false
193
194 This results in the following output:
195
196 .. code-block:: ansible-output
197
198 PLAY [Load SOPS-encrypted private key] ***************************************************************************
199
200 TASK [Create CSR with encrypted private key] *********************************************************************
201 ok: [localhost]
202
203 PLAY RECAP *******************************************************************************************************
204 localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
205
206 Afterwards, you will have a CSR ``ansible.com.csr`` for the encrypted private key ``keys/private_key.pem.sops``.
207
208 If you want to use Ansible to generate (or update) the encrypted private key, you can use the :ansplugin:`community.crypto.openssl_privatekey_pipe module <community.crypto.openssl_privatekey_pipe#module>` to generate (or update) the private key, and use the :ansplugin:`community.sops.sops_encrypt module <community.sops.sops_encrypt#module>` to write it to disk in encrypted form:
209
210 .. code-block:: yaml+jinja
211
212 ---
213 - name: Create SOPS-encrypted private key
214 hosts: localhost
215 gather_facts: false
216 tasks:
217 - block:
218 - name: Create private key
219 community.crypto.openssl_privatekey_pipe:
220 size: 2048
221 no_log: true # Always use this with openssl_privatekey_pipe!
222 register: private_key
223
224 - name: Write encrypted key to disk
225 community.sops.sops_encrypt:
226 path: keys/private_key.pem.sops
227 content_text: "{{ private_key.privatekey }}"
228
229 always:
230 - name: Wipe private key from Ansible's facts
231 # This is particularly important if the playbook doesn't end here!
232 set_fact:
233 private_key: ''
234
235 This playbook creates a new key on every run. If you want the private key creation to be idempotent, you need to do a little more work:
236
237 .. code-block:: yaml+jinja
238
239 ---
240 - name: Create SOPS-encrypted private key
241 hosts: localhost
242 gather_facts: false
243 tasks:
244 - block:
245 - name: Create private key
246 community.crypto.openssl_privatekey_pipe:
247 size: 2048
248 content: >-
249 {{ lookup(
250 'community.sops.sops',
251 'keys/private_key.pem.sops',
252 empty_on_not_exist=true
253 ) }}
254 no_log: true # Always use this with openssl_privatekey_pipe!
255 register: private_key
256
257 - name: Write encrypted key to disk
258 community.sops.sops_encrypt:
259 path: keys/private_key.pem.sops
260 content_text: "{{ private_key.privatekey }}"
261 when: private_key is changed
262
263 always:
264 - name: Wipe private key from Ansible's facts
265 # This is particularly important if the playbook doesn't end here!
266 set_fact:
267 private_key: ''
268
269 The :ansopt:`community.sops.sops#lookup:empty_on_not_exist=true` flag is needed to avoid the lookup to fail when the key does not yet exist. When this playbook is run twice, the output will be:
270
271 .. code-block:: ansible-output
272
273 PLAY [Create SOPS-encrypted private key] *************************************************************************
274
275 TASK [Create private key] ****************************************************************************************
276 ok: [localhost]
277
278 TASK [Write encrypted key to disk] *******************************************************************************
279 skipping: [localhost]
280
281 TASK [Wipe private key from Ansible's facts] *********************************************************************
282 ok: [localhost]
283
284 PLAY RECAP *******************************************************************************************************
285 localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
286
287 Working with encrypted data from other sources
288 ----------------------------------------------
289
290 You can use the :ansplugin:`community.sops.decrypt Jinja2 filter <community.sops.decrypt#filter>` to decrypt arbitrary data. This can be data read earlier from a file, returned from an action, or obtained through some other means.
291
292 For example, assume that you want to decrypt a file retrieved from a HTTPS server with the :ansplugin:`ansible.builtin.uri module <ansible.builtin.uri#module>`. To use the :ansplugin:`community.sops.sops lookup <community.sops.sops#lookup>`, you have to write it to a file first. With the filter, you can directly decrypt it:
293
294 .. code-block:: yaml+jinja
295
296 ---
297 - name: Decrypt file fetched from URL
298 hosts: localhost
299 gather_facts: false
300 tasks:
301 - name: Fetch file from URL
302 ansible.builtin.uri:
303 url: https://raw.githubusercontent.com/getsops/sops/master/functional-tests/res/comments.enc.yaml
304 return_content: true
305 register: encrypted_content
306
307 - name: Show encrypted data
308 debug:
309 msg: "{{ encrypted_content.content | ansible.builtin.from_yaml }}"
310
311 - name: Decrypt data and decode decrypted YAML
312 set_fact:
313 decrypted_data: "{{ encrypted_content.content | community.sops.decrypt | ansible.builtin.from_yaml }}"
314
315 - name: Show decrypted data
316 debug:
317 msg: "{{ decrypted_data }}"
318
319 The output will be:
320
321 .. code-block:: ansible-output
322
323 PLAY [Decrypt file fetched from URL] *****************************************************************************
324
325 TASK [Fetch file from URL] ***************************************************************************************
326 ok: [localhost]
327
328 TASK [Show encrypted data] ***************************************************************************************
329 ok: [localhost] => {
330 "msg": {
331 "dolor": "ENC[AES256_GCM,data:IgvT,iv:wtPNYbDTARFE810PH6ldOLzCDcAjkB/dzPsZjpgHcko=,tag:zwE8P+AwO1hrHkgF6pTbZw==,type:str]",
332 "lorem": "ENC[AES256_GCM,data:PhmSdTs=,iv:J5ugEWq6RfyNx+5zDXvcTdoQ18YYZkqesDED7LNzou4=,tag:0Qrom6J6aUnZMZzGz5XCxw==,type:str]",
333 "sops": {
334 "age": [],
335 "azure_kv": [],
336 "gcp_kms": [],
337 "hc_vault": [],
338 "kms": [],
339 "lastmodified": "2020-10-07T15:49:13Z",
340 "mac": "ENC[AES256_GCM,data:2dhyKdHYSynjXPwYrn9356wA7vRKw+T5qwBenI2vZrgthpQBOCQG4M6f7eeH3VLTxB4mN4CAchb25dsNRoGr6A38VruaSSAhPco3Rh4AlvKSvXuhgRnzZvNxE/bnHX1D4K5cdTb4FsJg/Ue1l7UcWrlrv1s3H3SwLHP/nf+suD0=,iv:6xBYURjjaQzlUOKOrs2NWOChiNFZVAGPJZQZ59MwX3o=,tag:uXD5VYme+c8eHcCc5TD2YA==,type:str]",
341 "pgp": [
342 {
343 "created_at": "2019-08-29T21:52:32Z",
344 "enc": "-----BEGIN PGP MESSAGE-----\n\nhQEMAyUpShfNkFB/AQgAlvpTj0NYqF4mQyIeM7wX2SHLb4U07/flpqDpp2W/30Pz\nAHA7sYrgP0l8BrjT2kwtgCN0cdfoIHJudezrNjANp2P5TbP2b9kYYNxpehzB9PFj\nFixnCS7Zp8WIt1yXr1TX+ANZoXLopVcRbMaQ5OdH7CN1pNQtMR+R3FR3X/IqKxiU\nDo1YLaooRJICUC8LJw2Tb4K+lYnTSqd/HalLGym++ivFvdDB1Ya1GhT1FswXidXK\nIRjsOVbxV0q5VeNOR0zxsheOvuHyCje16c7NXJtATJVWtTFABJB8u7CY5HhZSgq+\nrXJHyLHqVLzJ8E4WqHQkMNUlVcrqAz7glZ6xbAhfI9JeAYk5SuBOQOQ4yvASqH4K\nb0N3+/abluBY7YPqKuRZBiEtmcYlZ+zIHuOTP1rD/7L5VY8CwE5U8SFlEqwM7nQJ\n6/vtl6qngOFjwt34WrhZzUfLPB/wRV/m1Qv2kr0RNA==\n=Ykiw\n-----END PGP MESSAGE-----\n",
345 "fp": "FBC7B9E2A4F9289AC0C1D4843D16CEE4A27381B4"
346 }
347 ],
348 "unencrypted_suffix": "_unencrypted",
349 "version": "3.6.1"
350 }
351 }
352 }
353
354 TASK [Decrypt data] **********************************************************************************************
355 ok: [localhost]
356
357 TASK [Show decrypted data] ***************************************************************************************
358 ok: [localhost] => {
359 "msg": {
360 "dolor": "sit",
361 "lorem": "ipsum"
362 }
363 }
364
365 PLAY RECAP *******************************************************************************************************
366 localhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
367
368 Please note that if you put a Jinja2 expression in a variable, it will be evaluated **every time it is used**. Decrypting data takes a certain amount of time. If you need to use an expression multiple times, it is better to store its evaluated form as a fact with :ansplugin:`ansible.bulitin.set_fact <ansible.builtin.set_fact#module>` first. This can be important if decrypted data should be passed to a role
369
370 .. code-block:: yaml+jinja
371
372 ---
373 - name: Decrypt file fetched from URL
374 hosts: localhost
375 gather_facts: false
376 tasks:
377 - name: Fetch file from URL
378 ansible.builtin.uri:
379 url: https://raw.githubusercontent.com/getsops/sops/master/functional-tests/res/comments.enc.yaml
380 return_content: true
381 register: encrypted_content
382
383 # BAD: every time the role uses decrypted_data, the data will be decrypted!
384
385 - name: Call role with decrypted data
386 include_role:
387 name: myrole
388 vars:
389 role_parameter: "{{ encrypted_content.content | community.sops.decrypt | ansible.builtin.from_yaml }}"
390
391 # GOOD: the data is decrypted once before the role is called,
392
393 - name: Store decrypted data as fact
394 set_fact:
395 decrypted_data: "{{ encrypted_content.content | community.sops.decrypt | ansible.builtin.from_yaml }}"
396
397 - name: Call role with decrypted data
398 include_role:
399 name: myrole
400 vars:
401 role_parameter: "{{ decrypted_data }}"
402
403 Working with encrypted variables
404 --------------------------------
405
406 You can load encrypted variables similarly to the :ansplugin:`ansible.builtin.host_group_vars vars plugin <ansible.builtin.host_group_vars#vars>` with the :ansplugin:`community.sops.sops vars plugin <community.sops.sops#vars>`. If you need to load variables dynamically similarly to the :ansplugin:`ansible.builtin.include_vars action <ansible.builtin.include_vars#module>`, you can use the :ansplugin:`community.sops.load_vars action <community.sops.load_vars#module>`.
407
408 To use the vars plugin, you need to enable it in your Ansible config file (``ansible.cfg``):
409
410 .. code-block:: ini
411
412 [defaults]
413 vars_plugins_enabled = host_group_vars,community.sops.sops
414
415 See :ref:`VARIABLE_PLUGINS_ENABLED <VARIABLE_PLUGINS_ENABLED>` for more details on enabling vars plugins. Then you can put files with the following extensions into the ``group_vars`` and ``host_vars`` directories:
416
417 - ``.sops.yaml``
418 - ``.sops.yml``
419 - ``.sops.json``
420
421 (The list of extensions can be adjusted with :ansopt:`community.sops.sops#vars:valid_extensions`.) The vars plugin will decrypt them and you can use their unencrypted content transparently.
422
423 If you need to dynamically load encrypted variables, similar to the built-in :ansplugin:`ansible.builtin.include_vars action <ansible.builtin.include_vars#module>`, you can use the :ansplugin:`community.sops.load_vars action <community.sops.load_vars#module>` action. Please note that it is not a perfect replacement, since the built-in action relies on some hard-coded special casing in ansible-core which allows it to load the variables actually as variables (more precisely: as "unsafe" Jinja2 expressions which are automatically evaluated when used). Other action plugins, such as :ansplugin:`community.sops.load_vars#module`, cannot do that and have to load the variables as facts instead.
424
425 This is mostly relevant if you use Jinja2 expressions in the encrypted variable file. When :ansplugin:`ansible.builtin.include_vars#module` loads a variable file with expressions, these expressions will only be evaluated when the variable that defines them needs to be evaluated (lazy evaluation). Since :ansplugin:`community.sops.load_vars#module` returns facts, it has to directly evaluate expressions at load time. (For this, set its :ansopt:`community.sops.load_vars#module:expressions` option to :ansval:`evaluate-on-load`.) This is mostly relevant if you want to refer to other variables from the same file: this will not work, since Ansible does not know the other variable yet while evaluating the first. It will only "know" them as facts after all have been evaluated and the action finishes.
426
427 For the following example, assume you have the encrypted file ``keys/credentials.sops.yml`` which decrypts to:
428
429 .. code-block:: yaml
430
431 encrypted_password: foo
432 expression: "{{ inventory_hostname }}"
433
434 Consider the following playbook:
435
436 .. code-block:: yaml+jinja
437
438 ---
439 - name: Create SOPS-encrypted private key
440 hosts: localhost
441 gather_facts: false
442 tasks:
443 - name: Load encrypted credentials
444 community.sops.load_vars:
445 file: keys/credentials.sops.yml
446 expressions: ignore # explicitly do not evaluate expressions
447 # on load (this is the default)
448
449 - name: Show password
450 debug:
451 msg: "The password is {{ encrypted_password }}"
452
453 - name: Show expression
454 debug:
455 msg: "The expression is {{ expression }}"
456
457 Running it produces:
458
459 .. code-block:: ansible-output
460
461 PLAY [Create SOPS-encrypted private key] *************************************************************************
462
463 TASK [Load encrypted credentials] ********************************************************************************
464 ok: [localhost]
465
466 TASK [Show password] *********************************************************************************************
467 ok: [localhost] => {
468 "msg": "The password is foo"
469 }
470
471 TASK [Show expression] *******************************************************************************************
472 ok: [localhost] => {
473 "msg": "The expression is {{ inventory_hostname }}"
474 }
475
476 PLAY RECAP *******************************************************************************************************
477 localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
478
479 If you change the variable loading task to:
480
481 .. code-block:: yaml+jinja
482
483 - name: Load encrypted credentials
484 community.sops.load_vars:
485 file: keys/credentials.sops.yml
486 expressions: evaluate-on-load
487
488 The last task will now show the evaluated expression:
489
490 .. code-block:: ansible-output
491
492 TASK [Show expression] *******************************************************************************************
493 ok: [localhost] => {
494 "msg": "The expression is localhost"
495 }