ansible-role-for-splunk icon indicating copy to clipboard operation
ansible-role-for-splunk copied to clipboard

How to use ansible-role-for-splunk in your playbooks?

Open EsOsO opened this issue 2 years ago • 3 comments

Hi, I'm using the provided playbooks to install some new indexers and it works well. Now I'd like to execute some more steps before and after the "Splunk" part (eg. chowning the indexes directory to the splunk user) and here comes my question: how to reuse the role vars to avoid defining it in my own roles?

EsOsO avatar Jan 12 '23 09:01 EsOsO

Like this

--

- hosts:
    - all
  roles:
    - ../roles/splunk
  serial: 50
  vars:
    - deployment_task: your_custom_task.yml
    ```

nockstarr avatar Jan 12 '23 18:01 nockstarr

I know that. What I'm asking is how to use calculated vars like splunk_home in your plays.

I'm using like this:

---
- name: Install or upgrade Splunk
  hosts:
    - all
  roles:
    - ../roles/splunk
  vars:
    - deployment_task: check_splunk.yml

- name: Tune system for Splunk workload
  hosts:
    - all
  roles:
    - ../roles/splunk
  vars:
    - deployment_task: configure_os.yml

- name: Post installation steps
  hosts: all
  roles:
    - ../roles/common

I'd like to use the splunk role vars in my own role without the need to duplicate the logic or the definition.

EsOsO avatar Jan 13 '23 08:01 EsOsO

@EsOsO you can call the splunk role or specific task from the splunk role in your common role.

- name: do something
  include_role:
    name: splunk
    tasks_from: task.yml

Ces-Ces avatar Jan 13 '23 15:01 Ces-Ces