【问题标题】:Running ansible script in Azure DevOps pipeline在 Azure DevOps 管道中运行 ansible 脚本
【发布时间】:2019-03-26 19:31:10
【问题描述】:

我正在尝试在基于 Ubuntu 16.04 (Xenial 64) 的 Azure DevOps 管道的底层自定义 VM。

我可以看到,在各种现成的任务中,我可以将bash 脚本作为任务运行。

通过运行一个bash脚本我可以看到在Ubuntu环境下ansible被安装了,因为当在“Bash”类型的任务内容中输入sudo apt-get install ansible时,那么执行的Logs的输出管道说:

2018-10-22T16:33:00.7632392Z ansible is already the newest version (2.0.0.2-2ubuntu1.1).

在 Azure DevOps/pipelines 文档网站上没有关于 ansible 的信息,但该命令确实存在,而且我可以成功运行 apt-get install 之类的东西,所以我什至可以安装它以防万一它不存在.

我无法为 ansible 指定主机 (localhost),甚至无法将文件 /etc/ansible/hosts 更改为 sudo,因为我得到了“权限被拒绝”。

是否有可能在该 DevOps/管道环境中运行 ansible playbook?

我的想法是:

  • 克隆一个包含“使用管道进行测试的代码”的 git 存储库 以及配置 Ubuntu 环境的 ansible playbook
  • 然后将目录更改为 /home/vsts/work/1/s/(似乎 Azure DevOps/pipeline 用户被称为 vsts,当克隆 git 存储库时,它会转到 ~/1/s/ 目录)
  • 然后运行“Bash”类型的 Azure DevOps/管道任务,其中包含:
    • 调用ansible playbook(用于配置 Ubuntu 环境)
    • 在 git 存储库中调用 Makefile(以运行“测试”)

到目前为止,我在尝试以下变体时总是得到“权限被拒绝”:

sudo echo $(ifconfig eth0 | grep 'inet addr' | awk '{print $2 }' | sed 's/addr://g') >> /etc/ansible/hosts 
ansible-playbook ci/prepare-vm/azure-pipeline-vm-setup.yml -vvvv --extra-vars "cli_input_username=vsts"

或尝试通过-i 参数将eth0 IP 地址直接传递给命令ansible-playbook

  • 为什么即使安装了 ansible 包,我似乎也无法运行 ansible 脚本?
  • 如何在 Azure DevOps 管道中运行这个 ansible 脚本?

【问题讨论】:

    标签: azure ansible azure-devops azure-pipelines


    【解决方案1】:

    您可以使用带有 -i 标志的替代文件主机。

    例如

    ansible-playbook -i $(Build.SourcesDirectory)/hosts
    

    【讨论】:

      猜你喜欢
      • 2022-12-01
      • 1970-01-01
      • 2021-05-15
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-20
      相关资源
      最近更新 更多