【问题标题】:Passing BitBucket server credentials when using Ansible get_url使用 Ansible get_url 时传递 BitBucket 服务器凭据
【发布时间】:2021-06-24 18:15:11
【问题描述】:

我正在尝试编写一个 ansible 脚本来从本地 bitbucket 服务器下载文件(shell 脚本)。

目前代码如下。它要求输入 id 和 pw 输入,当我打印它时,它会打印正确的输出。

但是 get_url 调用返回一个 html 页面。输入的 Id / pw 确实可以访问相关的 BB 存储库。

以下不是将凭据传递给 bitbucket 存储库的正确方法吗?

---

- name: Deployment of infrastructure changes
  hosts: kafka_broker[0]
  vars:
    ansible_ssh_extra_args: "-o StrictHostKeyChecking=no"
    ansible_host_key_checking: false
    date: "{{ lookup('pipe', 'date +%Y%m%d-%H%M%S') }}"

  vars_prompt:
    - name: bb_username
      prompt: "User name for Bitbucket"
      private: no

    - name: bb_password
      prompt: "Password for "
      private: yes


  tasks:

    - name: Download connector scripts
      get_url:
        url: "http://bbserver:7990/projects/myproject/repos/myrepo/browse/scripts/{{ item }}"
        dest:  /var/scripts
        url_username: '{{ bb_username }}'
        url_password: '{{ bb_password }}'
      with_items:
        - script1.sh
        - script2.sh
        - script3.sh
      register: showdlstatus
      become: yes
      become_user: '{{ bb_username }}'

我应该如何修改上述脚本以从 BitBucket 下载文件>

谢谢

【问题讨论】:

  • (至少)两件事:1.你有with_items:,但在你的url:中没有提到{{ item }},所以这不太可能达到你的预期2.你没有说什么相反,您是否能够使用该 URL 语法卷曲这些脚本。没有人能猜出你的设置出了什么问题
  • 抱歉,这是在清理用于发布信息的 url 时的疏忽。使用的网址是url: "http://bbserver:7990/projects/myproject/repos/myrepo/browse/scripts/{{ item }}"。我可以使用 curl 从同一个 repo 下载文件。 curl命令格式为curl -k -L --verbose -X GET --user "${USERID}:${PASSWORD}" -o ${filename} bb_url输出文件的开头为-<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>Log in - Bitbucket</title><script> window.WRM=window.WRM||{};
  • 请不要将代码放在 cmets 中,那样会很糟糕。是的,这就是我所期望的(对于被忽略的凭据和 html 响应);对于 现代 平台,有一个用于特定 sha 的原始字节的专用 URL 方案(GH 使用 /raw/the-branch/the/file/name GL 使用 /-/raw/the-branch/the/file/name)并且身份验证通常是特殊需要,而不是 HTTP Basic
  • 我也尝试使用 - url: "bbserver:7990/projects/myproject/repos/myrepo/raw/scripts{{ item }}" 并通过将 ?at=refs%2Fheads%2Fmaster 添加到脚本名称来更改项目 - 比如- script1.sh?at=refs%2Fheads%2Fmaster 得到相同的结果 - 我如何确定需要什么身份验证?在 cURL 命令中 - 这是我在运行时要求的明文 id 密码,类似于 ansible 脚本
  • 通过不同的尝试和反复试验 - 我尝试的最后一个是 force_basic_auth: yes 并且成功了。 @mdaniel,如果这是正确的方法,我会将其添加为答案,因此遇到相同情况的人可以找到答案

标签: ansible credentials bitbucket-server geturl


【解决方案1】:

在脚本中添加 force_basic_auth: yes 解决了问题

任务:

- name: Download connector scripts
  get_url:
    url: "http://bbserver:7990/projects/myproject/repos/myrepo/raw/scripts/{{ item }}"
    dest:  /var/scripts
    url_username: '{{ bb_username }}'
    url_password: '{{ bb_password }}'
    **force_basic_auth: yes**
  with_items:
    - script1.sh
    - script2.sh
    - script3.sh

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多