From bdb07c7de9594d7771f2db42ecfc03b8316ef3ff Mon Sep 17 00:00:00 2001 From: enxebre Date: Fri, 17 Jul 2015 11:08:27 +0100 Subject: [PATCH] Dynamically looping. --- roles/frameworks/defaults/main.yml | 6 ++- roles/frameworks/tasks/cassandra.yml | 40 ---------------- roles/frameworks/tasks/main.yml | 48 ++++++++++++++++++- .../frameworks/templates/cassandra-config.j2 | 2 +- roles/mesos/defaults/main.yml | 1 + 5 files changed, 53 insertions(+), 44 deletions(-) delete mode 100644 roles/frameworks/tasks/cassandra.yml diff --git a/roles/frameworks/defaults/main.yml b/roles/frameworks/defaults/main.yml index d4e441f2..dca52205 100644 --- a/roles/frameworks/defaults/main.yml +++ b/roles/frameworks/defaults/main.yml @@ -2,8 +2,10 @@ # defaults file for frameworks frameworks_dcos_cli_image: capgemini/dcos-cli frameworks_zk_master_peers: "zk://{{ zookeeper_peers_nodes }}/mesos" -frameworks_mesos_master_url: "http://{{ ansible_ssh_host }}:5050" -frameworks_marathon_url: "http://{{ ansible_ssh_host }}:8080" +frameworks_mesos_master_url: "http://{{ ansible_ssh_host }}:{{ mesos_master_port }}" +frameworks_marathon_url: "http://{{ ansible_ssh_host }}:{{ marathon_port }}" frameworks_cassandra_enabled: false frameworks_cassandra_node_count: 1 +frameworks_list: + - cassandra diff --git a/roles/frameworks/tasks/cassandra.yml b/roles/frameworks/tasks/cassandra.yml deleted file mode 100644 index 158d7aa2..00000000 --- a/roles/frameworks/tasks/cassandra.yml +++ /dev/null @@ -1,40 +0,0 @@ -- name: create cassandra config directory - when: frameworks_cassandra_enabled - run_once: true - template: - src: cassandra-config.j2 - dest: /tmp/cassandra-config - mode: 0755 - sudo: yes - tags: - - cassandra - -- name: install dcos-cli cassandra package - when: frameworks_cassandra_enabled - run_once: true - docker: - name: cassandra - image: "{{ frameworks_dcos_cli_image }}" - state: started - command: "package install --options=/config --yes cassandra" - volumes: - - "/tmp/cassandra-config:/config" - env: - MESOS_MASTER_URL: "{{ frameworks_mesos_master_url }}" - MARATHON_URL: "{{ frameworks_marathon_url }}" - tags: - - cassandra - -- name: uninstall dcos-cli cassandra package - when: ! frameworks_cassandra_enabled - run_once: true - docker: - name: cassandra - image: "{{ frameworks_dcos_cli_image }}" - state: started - command: "package uninstall cassandra" - env: - MESOS_MASTER_URL: "{{ frameworks_mesos_master_url }}" - MARATHON_URL: "{{ frameworks_marathon_url }}" - tags: - - cassandra diff --git a/roles/frameworks/tasks/main.yml b/roles/frameworks/tasks/main.yml index a4080c14..0d3256f7 100644 --- a/roles/frameworks/tasks/main.yml +++ b/roles/frameworks/tasks/main.yml @@ -1,3 +1,49 @@ --- # tasks file for frameworks -- include: cassandra.yml +- name: "create config directory" + when: "frameworks_{{ item }}_enabled" + run_once: true + template: + src: "{{ item }}-config.j2" + dest: "/tmp/{{ item }}-config" + mode: 0755 + sudo: yes + tags: + - "{{ item }}" + with_items: + - "{{ frameworks_list }}" + +- name: "install dcos-cli package" + when: "frameworks_{{ item }}_enabled" + run_once: true + docker: + name: "{{ item }}" + image: "{{ frameworks_dcos_cli_image }}" + state: started + command: "package install --options=/config --yes {{ item }}" + volumes: + - "/tmp/{{ item }}-config:/config" + env: + MESOS_MASTER_URL: "{{ frameworks_mesos_master_url }}" + MARATHON_URL: "{{ frameworks_marathon_url }}" + tags: + - "{{ item }}" + with_items: + - "{{ frameworks_list }}" + +- name: "uninstall dcos-cli package" + when: "not frameworks_{{ item }}_enabled" + run_once: true + docker: + name: "{{ item }}" + image: "{{ frameworks_dcos_cli_image }}" + state: started + command: "package uninstall {{ item }}" + env: + MESOS_MASTER_URL: "{{ frameworks_mesos_master_url }}" + MARATHON_URL: "{{ frameworks_marathon_url }}" + tags: + - "{{ item }}" + with_items: + - "{{ frameworks_list }}" + diff --git a/roles/frameworks/templates/cassandra-config.j2 b/roles/frameworks/templates/cassandra-config.j2 index e31e667c..0e5b92c3 100644 --- a/roles/frameworks/templates/cassandra-config.j2 +++ b/roles/frameworks/templates/cassandra-config.j2 @@ -2,6 +2,6 @@ "mesos": {"master": "{{ frameworks_zk_master_peers }}"}, "cassandra": { "zk": "zk://{{ zookeeper_peers_nodes }}/cassandra-mesos", - "node-count": "{{ frameworks_cassandra_node_count }}" + "node-count": {{ frameworks_cassandra_node_count }} } } diff --git a/roles/mesos/defaults/main.yml b/roles/mesos/defaults/main.yml index e55d80da..1bcbe162 100644 --- a/roles/mesos/defaults/main.yml +++ b/roles/mesos/defaults/main.yml @@ -11,3 +11,4 @@ mesos_resources: "ports(*):[31000-32000]" mesos_slave_work_dir: "/tmp/mesos" mesos_ip: "{{ ansible_default_ipv4.address }}" mesos_hostname: "{{ ansible_ssh_host }}" +