Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I load a role without executing its tasks (to get the modules only)?

Tags:

ansible

I want to use the module mongodb_replication defined in greendayonfire.mongodb role.

I know I can use the module in my tasks after applying the role in the same play. But I don't want to apply the role (and execute all it's tasks). Is there any way to get to "include" the role without executing the tasks?

I want to have it like this

---
- hosts: mongodb-nodes
  become: true
  roles:
    - base
    - greendayonfire.mongodb
  vars:
    mongodb_package: mongodb-org
    mongodb_version: "3.2"
    mongodb_force_wait_for_port: true
    mongodb_net_bindip: 0.0.0.0
    mongodb_net_http_enabled: true
    mongodb_replication_replset: "rs1"
    mongodb_storage_prealloc: false
- hosts: mongodb-0
      tasks:
        - mongodb_replication: replica_set=rs1 host_name=item state=present
          with_items:
            - mongodb-0
            - mongodb-1
            - mongodb-2

where the second play is the one that runs the mongodb_replication module (only in the node mongodb-0). Right now it can't find the module.

I guess can I copy the module out of the role into my playbook but I will be cleaner if I could just import the module from the role (which I don't want to edit)

like image 957
RubenLaguna Avatar asked May 04 '16 11:05

RubenLaguna


1 Answers

I found that it's possible to load the role without executing the task by using the when: false clause when referring to the role. This loads the vars, defaults, modules, etc.

- hosts: mongodb-0
      roles:
        - role: greendayonfire.mongodb
          when: false
      tasks:
        - mongodb_replication: replica_set=rs1 host_name=item state=present
          with_items:
            - mongodb-0
            - mongodb-1
            - mongodb-2
like image 188
RubenLaguna Avatar answered Sep 29 '22 09:09

RubenLaguna