Azure DevOps Pipeline中的Ansible路径解析

h43kikqp  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(125)

我写了一个简单的剧本,因为我想自动配置部署到我的一些虚拟机:

---

- hosts: monitoring
  become: true
  roles:
    - monitoring

字符串
roles/monitoring/tasks文件

- name: Deploy Dashboards
  ansible.builtin.import_tasks:
    file: deploy-prometheus-alerts.yml


和任务文件

---

- name: Copy Prometheus alerts configuration
  ansible.builtin.copy:
    src: "{{ azdo_workspace }}/monitoring/config/"
    dest: "/opt/buka2/prometheus/config/"
    mode: '0644'
    group: 'domain users'
    remote_src: yes


azure-pipeline.yml

steps:
  - task: DownloadSecureFile@1
    name: SshKey
    displayName: "Download ssh private key"
    inputs:
      secureFile: "test.id.priv"

  - bash:  |
      ansible-playbook -v -i ./inventories/test/hosts.yml main.yml \
        --user testserviceuser \
        --key-file "$(SshKey.secureFilePath)" \
        -e "ansible_become_pass=$(ansible.test.pass)" \
        -e "azdo_workspace=$(Build.SourcesDirectory)"
    displayName: test copy file
    workingDirectory: ansible
    # Probably should be a better way
    # https://docs.ansible.com/ansible/latest/inventory_guide/connection_details.html#managing-host-key-checking
    env:
      ANSIBLE_HOST_KEY_CHECKING: False


ansible失败,出现错误:

fatal: [BUILD-AGENT]: FAILED! => {"changed": false, "msg": "Source /__w/1238/s/monitoring/config/ not found"}


从ansibleAngular 看,pwd是wird,当我做ansible.builtin.shell: pwd

"/home/svcazdevopstest@corp.itsroot.biz"


并且hostname已经指示了我的远程,但是ansible.builtin.copysrc参数说 “要复制到远程服务器的文件的本地路径”。 在我的情况下,我希望是构建代理的工作目录。
所以我真的很感激如果有人能解释这一切应该如何工作?

lstz6jyr

lstz6jyr1#

所以正确使用remote_src: yes参数很重要。在我的情况下,我正在寻找文件在错误的主机。

相关问题