如何在 windows 中创建 ansible galaxy 角色?

How to create ansible galaxy roles in windows?

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

我找不到在 windows 上创建/初始化角色的方法。我从这个问题 How to automatically install Ansible Galaxy roles? 中模糊地借鉴了一些想法,并将以下命令添加到我的剧本 create roles on 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 以在角色已创建时忽略错误。 这是正确的方法还是 another/better 在 windows 中执行此操作?

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

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

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

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

这是我通常做的事情:只需创建这些文件夹和 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 } 
}*