簡體   English   中英

如何使用 ansible 保險庫發布加密文件?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM