How to create ansible galaxy roles in windows?

亡梦爱人 提交于 2020-01-26 02:17:24

问题


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.

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

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 ?


回答1:


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:

  • tasks
  • handlers
  • templates
  • files
  • vars
  • meta

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

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



来源:https://stackoverflow.com/questions/46781461/how-to-create-ansible-galaxy-roles-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!