【问题标题】:How to create ansible galaxy roles in windows?如何在 Windows 中创建 Ansible Galaxy 角色?
【发布时间】:2018-03-28 15:10:59
【问题描述】:

我正在通过 micheal heap 从 ansible-beginner 到 pro 学习 ansible。 Windows 上似乎不支持 ansible。这本书建议改为从虚拟机运行 ansible。我使用 vagrant 启动了一个 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 以忽略错误。 这是正确的方法还是在 Windows 中有另一种/更好的方法?

【问题讨论】:

  • 是的,可能代码没有明确目标。我想创建一个空角色结构,然后将任务添加到空角色内的 main.yml 文件中,然后我打算使用该角色。我在 VMBox 上有 ubuntu 操作系统,而不是在我的电脑上。我打算在虚拟机上安装 wordpress、nginx、php 等。我想在 windows 上的文件夹中为每个角色创建角色,并在每次安装组件时重复使用它们。
  • 就这么做吧。我认为将 Ansible 用于人们通常使用的 vi 或他们最喜欢的编辑器没有意义。
  • 请解释你的答案。你说的我什么都不懂。在不使用 ansible 的情况下如何创建 ansible-galaxy 角色?这里的目的是学习ansible,而不是安装wordpress。我问如何在 windows 上创建一个空的 ansible Galaxy 角色?如果您不知道答案,请不要发布无用的无关cmets。

标签: windows ansible ansible-galaxy


【解决方案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 } 
}*

【讨论】:

    【解决方案2】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2014-10-03
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多