簡體   English   中英

Ansible:將公鑰添加到 bitbucket 並簽出 repo

[英]Ansible: Add public key to bitbucket and checkout the repo

我正在嘗試開發一個 Ansible 腳本,它將檢查從 bitbucket 到主機的 repo。 我有一個密鑰,我有一個 repo 並在 Ansible 中准備了模塊 git,它將檢查 repo。

如果我將 go 到 Bitbucket-> settings-> ssh 密鑰並手動從主機添加密鑰,則腳本將簽出 repo。

- name: Download the repository  
  git:
    key_file: /home/{{ device_user }}/.ssh/id_rsa
    repo: '{{ my_repo }}'
    dest: /home/{{ device_user }}/my_repo
    depth: '1'
    force: yes
    accept_hostkey: yes

所以它正在工作,到目前為止。

這里的問題是如何通過 Ansible自動添加到 Bitbucket? 如果 Ansible Controller 可以做到這一點,那就太好了,因為它已經有了密鑰。 但如果有其他方式我對他們開放。

我嘗試了 community.general.bitbucket_access_key 但它在“無法檢索訪問令牌...”時失敗,並且互聯網上沒有太多提示。 我沒能解決這個問題。

編輯:

我按照文檔說明安裝了模塊。 在 Bitbucket 上,我創建了 OAuth 使用者名稱的工作區設置:設備和帳戶、工作區、項目設置為讀取和存儲庫權限讀取和管理,如文檔所述。

- name: Create access key
  community.general.bitbucket_access_key:
    repository: 'my_repo'
    client_id: xxxxxxxxx # Key generated by Bitbucket
    client_secret: xxxxxxxxxxxxxx # Secret generated by Bitbucket
    username: my_name.admin
    key: '{{lookup("file", "/home/{{ device_user }}/.ssh/device.pub") }}'
    label: 'device'
    state: present

錯誤如下:

fatal: [169.254.155.9]: FAILED! => {"changed": false, "msg": "Failed to retrieve access token: {'url': 'https://bitbucket.org/site/oauth2/access_token', 'status': 400, 'content-security-policy-report-only': \"script-src 'unsafe-eval' 'strict-dynamic' 'unsafe-inline' 'self' http: https: https://d301sr5gafysq2.cloudfront.net; style-src 'self' 'unsafe-inline' https://aui-cdn.atlassian.com https://d301sr5gafysq2.cloudfront.net; report-uri https://web-security-reports.services.atlassian.com/csp-report/bb-website; default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob: *; connect-src bitbucket.org *.bitbucket.org bb-inf.net *.bb-inf.net id.atlassian.com analytics.atlassian.com as.atlassian.com api-private.stg.atlassian.com api-private.atlassian.com cofs.staging.public.atl-paas.net cofs.prod.public.atl-paas.net intake.opbeat.com api.media.atlassian.com api.segment.io xid.statuspage.io xid.atlassian.com xid.sourcetreeapp.com bam.nr-data.net bam-cell.nr-data.net sentry.io bqlf8qjztdtr.statuspage.io https://d301sr5gafysq2.cloudfront.net; object-src about:; base-uri 'self'\", 'server': 'nginx', 'vary': 'Accept-Language, Cookie', 'cache-control': 'no-cache, no-store, must-revalidate, max-age=0', 'content-type': 'application/json', 'x-b3-traceid': '05a9d3c28cad6147', 'x-dc-location': 'ash2', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', 'date': 'Mon, 22 Feb 2021 07:02:34 GMT', 'expires': 'Mon, 22 Feb 2021 07:02:34 GMT', 'x-served-by': 'app-3012', 'content-language': 'en', 'x-static-version': 'd4819e0e263d', 'x-render-time': '0.0134270191193', 'connection': 'close', 'x-version': 'd4819e0e263d', 'x-request-count': '2373', 'x-frame-options': 'SAMEORIGIN', 'content-length': '198', 'msg': 'HTTP Error 400: Bad Request', 'body': b'{\"error_description\": \"Cannot use client_credentials with a consumer marked as \\\\\"public\\\\\". Calls for auto generated consumers should use urn:bitbucket:oauth2:jwt instead.\", \"error\": \"invalid_grant\"}'}"}

我想重要的信息是:不能將 client_credentials 與標記為 \\"public\\" 的消費者一起使用

所以我將消費者設為私有:

我收到以下錯誤:

fatal: [169.254.155.9]: FAILED! => {"changed": false, "msg": "Failed to retrieve access token: {'url': 'https://bitbucket.org/site/oauth2/access_token', 'status': 400, 'content-security-policy-report-only': \"script-src 'unsafe-eval' 'strict-dynamic' 'unsafe-inline' 'self' http: https: https://d301sr5gafysq2.cloudfront.net; style-src 'self' 'unsafe-inline' https://aui-cdn.atlassian.com https://d301sr5gafysq2.cloudfront.net; report-uri https://web-security-reports.services.atlassian.com/csp-report/bb-website; default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob: *; connect-src bitbucket.org *.bitbucket.org bb-inf.net *.bb-inf.net id.atlassian.com analytics.atlassian.com as.atlassian.com api-private.stg.atlassian.com api-private.atlassian.com cofs.staging.public.atl-paas.net cofs.prod.public.atl-paas.net intake.opbeat.com api.media.atlassian.com api.segment.io xid.statuspage.io xid.atlassian.com xid.sourcetreeapp.com bam.nr-data.net bam-cell.nr-data.net sentry.io bqlf8qjztdtr.statuspage.io https://d301sr5gafysq2.cloudfront.net; object-src about:; base-uri 'self'\", 'server': 'nginx', 'vary': 'Accept-Language, Cookie', 'cache-control': 'no-cache, no-store, must-revalidate, max-age=0', 'content-type': 'application/json', 'x-b3-traceid': '859f3c3a6f0cdf50', 'x-dc-location': 'ash2', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', 'date': 'Mon, 22 Feb 2021 07:11:20 GMT', 'expires': 'Mon, 22 Feb 2021 07:11:20 GMT', 'x-served-by': 'app-3015', 'content-language': 'en', 'x-static-version': 'd4819e0e263d', 'x-render-time': '0.0334351062775', 'connection': 'close', 'x-version': 'd4819e0e263d', 'x-request-count': '3514', 'x-frame-options': 'SAMEORIGIN', 'content-length': '98', 'msg': 'HTTP Error 400: Bad Request', 'body': b'{\"error_description\": \"No callback uri defined for the OAuth client.\", \"error\": \"invalid_request\"}'}"}

這里的重要消息是No callback uri defined for the OAuth client

我知道這可以在消費者設置中設置,但我沒有解決這個問題。

我終於讓它工作了。

這只是 Bitbucket 中的設置。 我發現回調必須設置為: https://bitbucket.org/my_repo/

所以模塊 community.general.bitbucket_access_key 工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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