windowsansibleansible-galaxy

How to create ansible galaxy roles in windows?


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 ?


Solution

  • 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:

    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.