# test.yml --- - hosts: localhost become: no gather_facts: no tasks: - name: Run MongoDB cluster in Docker docker_container: name: "{{ item }}" image: "{{ image_name }}" command: "/sbin/init" state: started privileged: "{{ docker_privileged }}" mounts: - type: bind source: /sys/fs/cgroup target: /sys/fs/cgroup - type: bind source: /sys/fs/fuse target: /sys/fs/fuse - type: tmpfs target: /run - type: tmpfs target: /run/lock with_items: - mongo1 - mongo2 - mongo3 - hosts: mongo become: no gather_facts: no tasks: - name: gather tasks from all hosts setup: - hosts: "{{ target | default('mongo') }}" become: no gather_facts: yes roles: - role: greendayonfire.mongodb when: "'mongo_master' in group_names" - hosts: "{{ target | default('mongo') }}" become: no gather_facts: yes roles: - role: greendayonfire.mongodb when: "'mongo_replicas' in group_names"