1

我正在通过 micheal heap 从 ansible-beginner 到 pro 学习 ansible。Windows 上似乎不支持 ansible。这本书建议改为从虚拟机运行 ansible。我使用 vagrant 启动了一个 VMbox,上面有 ubuntu/trusty64。我能够成功地在它上面运行我的剧本。但是,我在创建 ansible-galaxy 角色时遇到了问题。

我找不到在 Windows 上创建/初始化角色的方法。我从这个问题中模糊地借用了想法如何自动安装 Ansible Galaxy 角色?并将以下命令添加到我的剧本中在 Windows 上创建角色 local_action: command ansible-galaxy init sush.util --init-path roles

---
- hosts: all
  gather_facts: false
  become: true
  tasks:
    - name: make sure we can connect
      ping:
    #ansible-galaxy
    - name: Init sush.util
      local_action: command ansible-galaxy init sush.util --init-path roles
      ignore_errors: true

ignore_errors=true如果角色已经创建,我还添加了忽略错误。这是正确的方法还是在 Windows 中有另一种/更好的方法?

4

2 回答 2

2

如果您的目标是在 Windows 上本地创建角色,则实际上不需要使用 Ansible Galaxy 来执行此操作。Ansible 角色只是一组文件夹。要创建sush.util角色,请创建一个名为的文件夹sush.util,然后在其中创建以下文件夹:

  • 任务
  • 处理程序
  • 模板
  • 文件
  • 变量

最后,在每个文件夹中创建一个名为main.yml包含---在顶部的文件。

您现在拥有一个可以运行的 Ansible 角色。您添加的任何任务都tasks/main.yml将被执行。

于 2017-10-17T13:57:42.883 回答
1

这是我通常做的:只需创建那些文件夹和 main.yml 文件

*$path = "c:\git\install-sqlserver"
$main = "main.yml"
$dir = "defaults","files","handlers","meta","tasks","templates","tests","vars"
foreach ($d in $Dir){
New-Item -Path $path -Name $d -ItemType "directory"
New-Item -Path "$path\$d" -Name $main -ItemType "file" -Value "---"
if ((Test-path $path )){
New-Item -Path $path -Name $main -ItemType "file" -Value "---" -ErrorAction SilentlyContinue } 
}*
于 2020-02-25T03:50:32.647 回答