简体   繁体   English

在 Azure DevOps 管道中运行 ansible 脚本

[英]Running ansible script in Azure DevOps pipeline

I am trying to customize the VM under the hood of an Azure DevOps pipeline based on Ubuntu 16.04 (Xenial 64).我正在尝试在基于 Ubuntu 16.04 (Xenial 64) 的 Azure DevOps 管道下自定义 VM。

I can see that I can run bash scripts as tasks, among various ready-made tasks.我可以看到,在各种现成的任务中,我可以将bash脚本作为任务运行。

By running a bash script I can see in the Ubuntu environment ansible is installed, because when typing sudo apt-get install ansible in the content of the task of type "Bash", then the output of the Logs of the execution of the pipeline says:通过运行 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).

From the Azure DevOps/pipelines documentation website there is no information regarding ansible , but the command is there indeed, and I can successfully run stuff like apt-get install , so I could even install it in case it was not there. Azure DevOps/pipelines 文档网站上没有关于ansible信息,但命令确实存在,我可以成功运行apt-get install类的东西,所以我什至可以安装它,以防它不存在。

I am not able to specify the host (localhost) for ansible, not even changing the file /etc/ansible/hosts as sudo because I get back "permission denied".我无法为 ansible 指定主机(localhost),甚至无法将文件/etc/ansible/hosts更改为sudo因为我返回“权限被拒绝”。

Is it possible at all to run ansible playbooks in that DevOps/pipeline environment?是否有可能在 DevOps/管道环境中运行 ansible playbook?

My idea was to:我的想法是:

  • clone a git repository containing the "code to test with the pipeline" and the ansible playbook to configure the Ubuntu environment克隆一个包含“使用管道测试的代码”和 ansible playbook 的 git 存储库来配置 Ubuntu 环境
  • then changing directory to /home/vsts/work/1/s/ (it seems the Azure DevOps/pipeline user is called vsts and when cloning a git repository then it goes to that ~/1/s/ directory)然后将目录更改为/home/vsts/work/1/s/ (似乎 Azure DevOps/pipeline 用户称为vsts并且在克隆 git 存储库时它会转到该~/1/s/目录)
  • then run an Azure DevOps/pipeline task of type "Bash" containing:然后运行“Bash”类型的 Azure DevOps/pipeline 任务,其中包含:
    • an invocation of the ansible playbook (to configure the Ubuntu environment)调用ansible playbook(配置 Ubuntu 环境)
    • an invocation of the Makefile in the git repository (to run "the tests")调用 git 存储库中的Makefile (运行“测试”)

So far I've always got back "permission denied" when trying variations of:到目前为止,在尝试以下变体时,我总是得到“权限被拒绝”:

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"

or trying to pass the eth0 IP address directly to the command ansible-playbook via the -i parameter或者尝试通过-i参数将eth0 IP 地址直接传递给命令ansible-playbook

  • Why it seems I can not run an ansible script even if the ansible package is installed?为什么即使安装了 ansible 包,我似乎也无法运行 ansible 脚本?
  • How can I run this ansible script in an Azure DevOps pipeline?如何在 Azure DevOps 管道中运行这个 ansible 脚本?

You can use an alternative file hosts with the flag -i.您可以使用带有标志 -i 的替代文件主机。

Eg例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Azure Devops 中获取正在运行的 devops 管道实例 - Get running instances of devops pipeline in Azure Devops 在运行 Azure DevOps 管道时,如果我们不给管道的 powershell 脚本中使用的变量任何值 - While running Azure DevOps pipeline, If we dont give any value to the variable which is used in powershell script of pipeline 在 Azure Devops 中,如何在运行 shell 脚本的“Azure CLI task v.2”中使用管道变量? - In Azure Devops, how can i use pipeline variables in a “Azure CLI task v.2” running shell script? azure devops 管道脚本给出了 bash 错误 - azure devops pipeline script is giving bash error Azure DevOps 管道中的命令行脚本出错 - Error with Command Line Script in Azure DevOps Pipeline Azure devops 管道中的命令行脚本错误 - Command line script error in Azure devops pipeline Azure DevOps 管道条件脚本 arguments - Azure DevOps Pipeline conditional script arguments Azure Devops Pipeline 中的 Python 脚本执行 - Python script execution in Azure Devops Pipeline 当条件符合 azure devops 管道的 ansible 任务中的主机名时 - when condition as per hostname in ansible task of azure devops pipeline 在自动化脚本中下载 excel,但是在 azure devops 管道中运行时会在哪里下载? - Downloading excel in automation script , but where it will be download when running in azure devops pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM