[英]How to post encrypted file using ansible vault?
有没有办法使用 ansible.builtin.uri 模块发布/放置加密文件,同时从保险库无缝解密? 或者是否有安全的解决方法(即安全的任务序列?)。
用例是上传一个许可证文件,该文件使用 ansible 保险库加密存储在项目的 roles/the_role/files 文件夹中。
ansible.builtin.uri 模块能够找到加密文件,但在上传前不会解密。
- name: "Nexus Update License: Uploading new License file"
ansible.builtin.uri:
url: "http://{{ inventory_hostname }}:{{ nexus_default_port }}{{ nexus_default_context_path | regex_replace('\\/$', '')}}/service/rest/v1/system/license"
user: "{{ nexus_admin_account }}"
password: "{{ nexus_admin_password }}"
headers:
Content-Type: application/octet-stream
method: POST
force_basic_auth: yes
status_code: 200,204
src: "license.lic.enc" # this uploads the license still encrypted...
这个问题类似,但我不能使用复制模块: How to upload encrypted file using ansible vault?
我无法找到一种方法来上传文件,同时从保险库中即时解密文件。
一种解决方法是将文件上传到远程主机,使用它,然后确保在任何情况下都将其删除。
这比在运行 ansible 的主机上解密文件要好,因为其他用户可能可以访问它,而 ansible 执行的任务应该非常快。
# The following is slightly better as it will remove the license after use
- name: "Deploy new license"
block:
- name: "Copy license file"
ansible.builtin.copy:
src: "{{ nexus_license_file }}"
dest: "/tmp/license"
owner: "{{ nexus_os_user }}"
group: "{{ nexus_os_group }}"
mode: 0400
- name: "Nexus Update License ({{ ansible_hostname }}): Uploading new License file"
ansible.builtin.uri:
url: "http://{{ inventory_hostname }}:{{ nexus_default_port }}{{ nexus_default_context_path | regex_replace('\\/$', '')}}/service/rest/v1/system/license"
user: "{{ nexus_admin_account }}"
password: "{{ nexus_admin_password }}"
headers:
Content-Type: application/octet-stream
method: POST
force_basic_auth: yes
status_code: 200,204
src: "/tmp/license"
remote_src: true
always: # Always remove the license file
- name: "Remove license file"
ansible.builtin.file:
path: "/tmp/license"
state: absent
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.