我试图在基于Ubuntu 16.04(Xenial 64)的Azure DevOps管道的引擎下自定义VM .

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

通过运行bash脚本,我可以在Ubuntu环境中看到安装了 ansible ,因为在"Bash"类型的任务内容中输入 sudo apt-get install ansible 时,管道执行日志的输出说:

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 ,因为我得到了"permission denied" .

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

我的想法是:

  • 克隆包含"code to test with the pipeline"和ansible playbook的git存储库以配置Ubuntu环境

  • 然后将目录更改为 /home/vsts/work/1/s/ (似乎Azure DevOps /管道用户被称为 vsts ,当克隆git存储库时,它会转到 ~/1/s/ 目录)

  • 然后运行类型为"Bash"的Azure DevOps /管道任务,其中包含:

  • 调用 ansible playbook(配置Ubuntu环境)

  • 在git存储库中调用 Makefile (运行"the tests")

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

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脚本?