How to get latest versions of roles using galaxy?

19 views
Skip to first unread message

Zhomart Mukhamejanov

unread,
Nov 8, 2016, 2:13:06 PM11/8/16
to Ansible Project
Currently I'm using a role with it's dependencies. Author of the role fixed some major bugs but didn't pushed the release to the galaxy.ansible.com.

I want to get latest version of the role and it's dependencies from github. How can I do it?

Zhomart Mukhamejanov

unread,
Nov 8, 2016, 2:38:32 PM11/8/16
to Ansible Project
Ok, I've created simple script for that.

.roles-list.yml

```
- name: lesmyrmidons.mongodb
  github: lesmyrmidons/ansible-role-mongodb
- name: Graylog2.graylog-ansible-role
  github: Graylog2/graylog-ansible-role
```

./update-roles

```
#!/usr/bin/env ruby

require 'yaml'
require 'tmpdir'


root = Pathname.new(File.expand_path(__dir__))
roles_list = YAML.load(File.read('.roles-list.yml'))


def command(cmd)
  p cmd
  system cmd
end

roles_list.each do |role|
  puts "\nProcessing #{role['name']}"


  dir = Dir.mktmpdir('ansible')
  command "cd #{dir}; curl -L #{url} | tar -xf -"

  dest = root.join("roles", role['name'])
  FileUtils.rm_rf(dest)
  FileUtils.mkdir_p(dest)

  src = dir
  if Dir.new(dir).count == 3
    name = Dir.new(dir).to_a.detect { |f| f[0] != '.' }
    src = File.join(dir, name)
  end

  Dir.new(src).each do |f|
    next if f == '.' || f == '..'
    FileUtils.mv(File.join(src, f), dest)
  end

  FileUtils.rm_rf(dir)
end

puts "Done!"
```

Kai Stian Olstad

unread,
Nov 8, 2016, 3:23:40 PM11/8/16
to ansible...@googlegroups.com
On 08. nov. 2016 20:38, Zhomart Mukhamejanov wrote:
> Ok, I've created simple script for that.
>
> .roles-list.yml
>
> ```
> - name: lesmyrmidons.mongodb
> github: lesmyrmidons/ansible-role-mongodb
> - name: Graylog2.graylog-ansible-role
> github: Graylog2/graylog-ansible-role

ansible-galaxy can do that for you.

Something like this(not tested)

.roles-list.yml
- src: https://github.com/lesmyrmidons/ansible-role-mongodb
name: lesmyrmidons.mongodb
- src: https://github.com/Graylog2/graylog-ansible-role
name: Graylog2.graylog-ansible-role

ansible-galaxy install -r .roles-list.yml

Check this link for more information
https://docs.ansible.com/ansible/galaxy.html#installing-roles

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages