[英]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:我的想法是:
/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/
目录)ansible
playbook (to configure the Ubuntu environment)ansible
playbook(配置 Ubuntu 环境)Makefile
in the git repository (to run "the tests")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
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.