1

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 ?

sushrut619
  • 843
  • 8
  • 20
  • Yeah, probably the code does not make it clear the objective. I want to create an empty role structure, then I go and add tasks to main.yml files inside the empty roles and then I plan to use the role. I have ubuntu OS on VMBox, not on my computer. I plan to install wordpress, nginx, php etc on the VM. I want to create roles in a folder on windows for each and reuse them each time I want a component installed. – sushrut619 Oct 17 '17 at 02:59
  • Just do it. I don't see a point in employing Ansible for what people usually use `vi` or their other favourite editor. – techraf Oct 17 '17 at 04:04
  • Kindly, explain your answer. I don't understand anything of what you said. How would you create ansible-galaxy role without using ansible ? The purpose here is to learn ansible, not install wordpress. I asked how to create an empty ansible galaxy role on windows ? If you don't know the answer, please don't post useless irrelevant comments. – sushrut619 Oct 17 '17 at 13:38

2 Answers2

3

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.

Michael Heap
  • 371
  • 1
  • 2
1

This is what I usually do : Just create those folders and main.yml file

*$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 } 
}*
coorsktm
  • 11
  • 2