# test.yml --- - hosts: localhost become: no gather_facts: no tasks: - name: Copy environmnet file copy: src: etc/environment dest: /tmp/environment - name: Copy Squid config copy: src: etc/squid/squid.conf dest: /tmp/squid.conf - name: Create a network docker_network: name: MongoDBTestingNet - name: Run Proxy in Docker docker_container: name: proxy image: sameersbn/squid state: started volumes: - /tmp/squid.conf:/etc/squid/squid.conf:ro networks: - name: MongoDBTestingNet aliases: - proxy networks_cli_compatible: yes - 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 volumes: - /tmp/environment:/etc/environment:ro networks: - name: MongoDBTestingNet aliases: - "{{ item }}" networks_cli_compatible: yes with_items: - mongo1 - mongo2 - mongo3 - hosts: mongo become: no gather_facts: yes tasks: - name: Set proxy for apt copy: src: etc/apt/apt.conf.d/proxy.conf dest: /etc/apt/apt.conf.d/proxy.conf when: ansible_os_family == "Debian" - name: Set proxy for yum ini_file: path: /etc/yum.conf section: main option: proxy value: http://proxy:3128 when: ansible_os_family == "RedHat" - 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"