diff --git a/ansible.yml b/ansible.yml new file mode 100644 index 0000000..9485552 --- /dev/null +++ b/ansible.yml @@ -0,0 +1,55 @@ +--- +- hosts: rap + remote_user: root + vars: + rap: + port: 65000 + tasks: + - name: install dependencies + package: + name: "{{ item }}" + state: present + loop: + - rsync + - git + - tinc + - name: iptables + iptables: + action: append + chain: INPUT + table: filter + destination_port: "{{ rap.port }}" + protocol: "{{ item }}" + jump: ACCEPT + loop: + - tcp + - udp + - name: install rap + git: + repo: "https://0xacab.org/pip/rap.git" + dest: "/root/rap" + - name: node name + shell: 'echo {{ inventory_hostname }} | cut -d . -f 1' + register: node_name + - stat: + path: "/root/rap/hosts/{{ node_name.stdout }}" + register: node_exists + - name: init node + when: "node_exists.stat.exists == False" + shell: "cd /root/rap && ./rap init -a {{ inventory_hostname }} -p {{ rap.port }} {{ node_name.stdout }}" + - name: fetch hosts files + fetch: + flat: true + src: "/root/rap/hosts/{{ node_name.stdout }}" + dest: "./hosts/{{ node_name.stdout }}" + - name: copy hosts files + copy: + src: "./hosts/" + dest: "/root/rap/hosts/" + - file: + state: absent + path: "/root/rap/hosts/nufla" + - name: connectto + shell: 'cd /root/rap && for host in ./hosts/*; do test "./hosts/{{ node_name.stdout }}" = "${host}" && continue ; basename "${host}" | xargs -r ./rap connectto "{{ node_name.stdout }}"; done' + - name: install node + shell: "cd /root/rap && ./rap install {{ node_name.stdout }}"