<commit_before>- hosts: localhost
  name: init
  connection: local
  gather_facts: yes
  roles: 
    - scenario
    - common
  tags:
    - init

  tasks:
    - name: Create scenario name
      set_fact: scenario_name="scenario-{{ ansible_date_time.epoch }}-{{ number_of_nodes }}-{{ raiden_per_node }}"

    - include: roles/common/tasks/scenario_ami_id_from_name.yaml

    - name: Provision a set of instances
      local_action:
        module: ec2
        # this allows to refer to them later via 'hosts: key_raiden'
        key_name: raiden
        region: "{{ region }}"
        group: raiden
        instance_type: "{{ instance_type }}" 
        image: "{{ scenario_ami_id }}"
        wait: true
        count: "{{ number_of_nodes }}"
        instance_tags:
          Name: Scenario
          Scenario: "{{ scenario_name }}"
      register: ec2

    - name: Add all instance public IPs to host group
      add_host: hostname={{ item.public_ip }} groups=tag_Name_Scenario
      with_items: "{{ ec2.instances }}"

    - name: Collect all private IPs for use in configuration to 'node_ip'
      set_fact: node_ips="{{ ec2.instances | map(attribute='private_ip') | list }}"

    - name: Wait for SSH to come up
      wait_for: host={{ item.public_ip }} port=22 delay=60 timeout=320 state=started
      with_items: "{{ ec2.instances }}"

    - name: debug node_ips
      debug:
        var: node_ips

    - name: register scenario folder
      set_fact: scenario_folder="/tmp/{{ scenario_name }}"
    
    - name: create scenario global folder
      local_action:
        module: file
        path: "{{ scenario_folder }}"
        state: directory

    - name: create scenario folders
      local_action:
        module: file
        path: "{{ scenario_folder }}/{{ item }}/geth"
        state: directory
      with_items: "{{ node_ips }}"

    - name: store node_ips in scenario folder
      copy:
        content: 
          node_ips: "{{ node_ips }}"
        dest: "{{ scenario_folder }}/node_ips.json"


- hosts: tag_Name_Scenario
  name: init geth 
  remote_user: "{{ remote_user }}"
  gather_facts: true
  roles:
    - scenario 
    - common
  tags:
    - init_geth

  tasks:
    - include: roles/scenario/tasks/read_scenario_params.yaml

    - name: run 'geth_commands'
      local_action:
        module: shell
        chdir: "../"
        cmd: "python config_builder.py geth_commands {{ node_ips | join(' ') }}"
      register: geth_commands


    - name: store geth_commands
      copy:
        content:
          geth_commands: "{{ geth_commands }}"
        dest: "{{ scenario_folder }}/geth_commands.json"



- hosts: tag_Name_Scenario
  name: init geth 
  remote_user: "{{ remote_user }}"
  gather_facts: true
  roles:
    - scenario 
    - common
  tags:
    - terminate

  tasks:
    # Collect instance id: http://stackoverflow.com/a/27307254 
    - action: ec2_facts

    - name: shutdown all ec2.instances (pass '-e keep=True' if you actually want to use the scenario!)
      local_action:
        module: ec2
        region: "{{ region }}"
        state: absent
        instance_ids: "{{ ansible_ec2_instance_id }}"
      when: keep is not defined
<commit_msg>WIP: Add raiden configuration in scenario-folder #61 #63<commit_after>- hosts: localhost
  name: init
  connection: local
  gather_facts: yes
  roles: 
    - scenario
    - common
  tags:
    - init

  tasks:
    - name: Create scenario name
      set_fact: scenario_name="scenario-{{ ansible_date_time.epoch }}-{{ number_of_nodes }}-{{ raiden_per_node }}"

    - include: roles/common/tasks/scenario_ami_id_from_name.yaml

    - name: Provision a set of instances
      local_action:
        module: ec2
        # this allows to refer to them later via 'hosts: key_raiden'
        key_name: raiden
        region: "{{ region }}"
        group: raiden
        instance_type: "{{ instance_type }}" 
        image: "{{ scenario_ami_id }}"
        wait: true
        count: "{{ number_of_nodes }}"
        instance_tags:
          Name: Scenario
          Scenario: "{{ scenario_name }}"
      register: ec2

    - name: Add all instance public IPs to host group
      add_host: hostname={{ item.public_ip }} groups=tag_Name_Scenario
      with_items: "{{ ec2.instances }}"

    - name: Collect all private IPs for use in configuration to 'node_ip'
      set_fact: node_ips="{{ ec2.instances | map(attribute='private_ip') | list }}"

    - name: Wait for SSH to come up
      wait_for: host={{ item.public_ip }} port=22 delay=60 timeout=320 state=started
      with_items: "{{ ec2.instances }}"

    - name: debug node_ips
      debug:
        var: node_ips

    - name: register scenario folder
      set_fact: scenario_folder="/tmp/{{ scenario_name }}"
    
    - name: create scenario global folder
      local_action:
        module: file
        path: "{{ scenario_folder }}"
        state: directory

    - name: create scenario folders
      local_action:
        module: file
        path: "{{ scenario_folder }}/{{ item }}/geth"
        state: directory
      with_items: "{{ node_ips }}"

    - name: store node_ips in scenario folder
      copy:
        content: 
          node_ips: "{{ node_ips }}"
        dest: "{{ scenario_folder }}/node_ips.json"


- hosts: localhost 
  name: prepare geth 
  gather_facts: true
  roles:
    - scenario 
    - common
  tags:
    - prepare_geth

  tasks:
    - include: roles/scenario/tasks/read_scenario_params.yaml

    - name: run 'geth_commands'
      shell:
        chdir: "../"
        cmd: "python config_builder.py geth_commands {{ node_ips | join(' ') }}"
      register: geth_commands


    - name: store geth_commands
      copy:
        content:
          geth_commands: "{{ geth_commands }}"
        dest: "{{ scenario_folder }}/geth_commands.json"

    - name: put geth_command per node
      copy:
        content: "#!/usr/bin/env sh\n{{ geth_commands[item] }}"
      dest: "{{ scenario_folder }}/{{ item }}/geth/start.sh"
      mode: a+rx
      with_items: "{{ node_ips }}"

    - name: put static-bootnodes.json per node
      copy:
        content: "{{ geth_commands.static_bootnodes }}"
        dest: "{{ scenario_folder }}/{{ item }}/geth/static-bootnodes.json"
      with_items: "{{ node_ips }}"

    - name: create default account (for mining)
      shell:
        chdir: "../"
        cmd: python config_builder account_file
      register: account_file

    - name: store account file per node
      copy:
        content: "{{ account_file }}"
        dest: "{{ scenario_folder }}/{{ item }}/geth/keystore/default.json"
      with_items: "{{ node_ips }}"

    - name: create blockchain config (genesis & raiden flags)
      shell:
        chdir: "../"
        cmd: "python config_builder.py full_genesis {{ raiden_per_node }} {{ node_ips | join(' ') }}"
      register: blockchain_config

    - name: store genesis
      copy:
        content: "{{ blockchain_config }}"
        dest: "{{ scenario_folder }}/{{ item }}/geth/genesis.json"
      with_items: "{{ node_ips }}"

    - name: store contract_flags
      copy:
        content: "{{ blockchain_config.config.raidenFlags }}"
        dest: "{{ scenario_folder }}/{{ item }}/raiden_flags.txt"
      with_items: "{{ node_ips }}"

- hosts: localhost
  name: prepare raiden
  gather_facts: no
  roles:
    - scenario
    - common
  tags:
    - prepare_raiden

  tasks:
    - include: roles/scenario/tasks/read_scenario_params.yaml

    - name: create raiden node_list
      shell:
        chdir: "../"
        cmd: "python config_builder.py accounts {{ raiden_per_node }} {{ node_ips | join(' ') }}"
      register: raiden_accounts

    - name: create raiden instance folders
      file:
        path: "{{ scenario_folder }}/{{ item.key.split(':').0 }}/{{ item.key.split(':').1 }}"
        state: directory
      with_dict: "{{ raiden_accounts }}"

    - name: store private key per raiden node
      copy:
        content: "{{ item.value.privatekey }}"
        path: "{{ scenario_folder }}/{{ item.key.split(':').0 }}/{{ item.key.split(':').1 }}/privatekey.txt"
      with_dict: "{{ raiden_accounts }}"

    - name: store address per raiden node
      copy:
        content: "{{ item.value.address }}"
        path: "{{ scenario_folder }}/{{ item.key.split(':').0 }}/{{ item.key.split(':').1 }}/address.txt"
      with_dict: "{{ raiden_accounts }}"


- hosts: tag_Name_Scenario
  name: terminate
  remote_user: "{{ remote_user }}"
  gather_facts: true
  roles:
    - scenario 
    - common
  tags:
    - terminate

  tasks:
    # Collect instance id: http://stackoverflow.com/a/27307254 
    - action: ec2_facts

    - name: shutdown all ec2.instances (pass '-e keep=True' if you actually want to use the scenario!)
      local_action:
        module: ec2
        region: "{{ region }}"
        state: absent
        instance_ids: "{{ ansible_ec2_instance_id }}"
      when: keep is not defined

{'fraction_non_alphanumeric': 0.12412862604002699, 'fraction_numerical': 0.006521250281088374, 'mean_word_length': 2.366767600302801, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1991711', 'n_tokens_mistral': 2874, 'n_tokens_neox': 2770, 'n_words': 698}