如何在 Windows 中创建 ansible 星系角色? [英] How to create ansible galaxy roles in windows?

查看:27
本文介绍了如何在 Windows 中创建 ansible 星系角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am learning ansible from ansible-beginner to pro by micheal heap. It seems that ansible is not supported on windows. The book suggests running ansible from a virtual machine instead. I started a VMbox using vagrant, which has ubuntu/trusty64 on it. I am successfully able to run my playbooks on it. However, I ran into an issue when creating ansible-galaxy roles.

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

I could not find a way to create/ initialize a role on windows. I vaguely borrowed ideas from this question How to automatically install Ansible Galaxy roles? and added the following command to my playbook 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 中还有其他/更好的方法?

I also added ignore_errors=true to ignore the errors if the role has already been created. Is this the correct approach or is there another/better to do this in windows ?

推荐答案

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

If your aim is to create a role locally on Windows, you don't actually need to use Ansible Galaxy to do that. An Ansible role is just a set of folders. To create a sush.util role, create a folder named sush.util and then create the following folders inside that:

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

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

Finally, inside each of these folders create a file named main.yml that contains --- at the top.

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

You now have an Ansible role that you can run. Any tasks you add to tasks/main.yml will be executed.

这篇关于如何在 Windows 中创建 ansible 星系角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆