Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ansible collection support #791

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

tod-uma
Copy link
Contributor

@tod-uma tod-uma commented Mar 8, 2024

This PR makes it possible to use the splunk-ansible repository with ansible-galaxy as a collection. This makes it useful to integrate splunk-ansible with other ansible projects.

For example, I use this to add the splunk universal forwarder to all of our machines as a part of our bootstrap process. Here is the code I can now use:

collections/requirements.yml

collections:
  -  source: <url to repo>                
     version: ansible-collection
     type: git

and run the following command to install the collection:

ansible-galaxy collection install -vvv -r collections/requirements.yml --force

then in my playbook (splunk_universal_forwarder.yml):

- name: splunk_universal_forwarder playbook                                     
    hosts: splunk_universal_forwarder                                             
    become: true                                                                  
    collections: 
      -  splunk.splunk_ansible                                            
    vars:                                                                         
      splunk: "{{ splunk_universal_forwarder }}"  # set the splunk variable however you want, we use group_vars variables                                
    tasks:
    - name: "prepare the machine here"                                               
      ansible.builtin.debug:                                                    
        msg: "put tasks to get the machine ready here"
    - name: "install the forwarder"                                             
      ansible.builtin.include_role:                                             
        name: splunk_universal_forwarder

you can then run the playbook like:

ansible-playbook -v --limit <target host> splunk_universal_forwarder.yml

I had to move the library directory to plugins/modules so that ansible could find the plugins correctly in the collection environment. This should more universally work.

The galaxy.yml I build is very minimal, just enough to get it to work. I would expect it would need modified to better match the project.

Documentation on ansible collection development can be found at https://docs.ansible.com/ansible/latest/dev_guide/developing_collections.html

Documentation on ansible galaxy support can be found at https://docs.ansible.com/ansible/latest/dev_guide/collections_galaxy_meta.html#collections-galaxy-meta

@tod-uma tod-uma marked this pull request as ready for review March 8, 2024 15:19
@tod-uma tod-uma requested a review from a team as a code owner March 8, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant