|
| 1 | +--- |
| 2 | +# tasks file for bootstrap |
| 3 | +#This task generates the vagrant file for the VMs to be created. |
| 4 | + |
| 5 | +- name: Template the VagrantFile.j2 configuration file to ../Vagrantfile |
| 6 | + template: |
| 7 | + src: VagrantFile.j2 |
| 8 | + dest: ../Vagrantfile |
| 9 | + delegate_to: localhost |
| 10 | + |
| 11 | +- name: Template the inventory.ini.j2 configuration file to invetory.ini |
| 12 | + template: |
| 13 | + src: inventory.ini.j2 |
| 14 | + dest: inventory.ini |
| 15 | + delegate_to: localhost |
| 16 | + |
| 17 | +- name: Refresh inventory to ensure that the new generated one is used |
| 18 | + meta: refresh_inventory |
| 19 | + |
| 20 | +- name: Find and save in a local variable all host_vars files |
| 21 | + find: |
| 22 | + paths: ./host_vars |
| 23 | + patterns: "*.yml" |
| 24 | + register: files_to_delete |
| 25 | + |
| 26 | +- name: Delete all the host_vars files |
| 27 | + file: |
| 28 | + path: "{{ item.path }}" |
| 29 | + state: absent |
| 30 | + with_items: "{{ files_to_delete.files }}" |
| 31 | + |
| 32 | +- name: Creating the "host_vars" file for each k8s' master-node |
| 33 | + file: |
| 34 | + path: ./host_vars/{{item}}.yml |
| 35 | + state: touch |
| 36 | + mode: u=rw,g=r,o=r |
| 37 | + loop: "{{ groups.k8s_master_nodes }}" |
| 38 | + |
| 39 | +- name: Populating the k8s-master-nodes host_vars files with the node ip |
| 40 | + lineinfile: |
| 41 | + path: "./host_vars/{{ item.0 }}.yml" |
| 42 | + line: "node_ip: {{ item.1 }}" |
| 43 | + loop: "{{ groups.k8s_master_nodes|zip(k8s_master_nodes_ips)|list }}" |
| 44 | + |
| 45 | +- name: Creating the "host_vars" file for each k8s' worker-node |
| 46 | + file: |
| 47 | + path: ./host_vars/{{item}}.yml |
| 48 | + state: touch |
| 49 | + mode: u=rw,g=r,o=r |
| 50 | + loop: "{{ groups.k8s_worker_nodes }}" |
| 51 | + |
| 52 | +- name: Populating the k8s-worker-nodes host_vars files with the node ips |
| 53 | + lineinfile: |
| 54 | + path: "./host_vars/{{ item.0 }}.yml" |
| 55 | + line: "node_ip: {{ item.1 }}" |
| 56 | + loop: "{{ groups.k8s_worker_nodes|zip(k8s_worker_nodes_ips)|list }}" |
| 57 | + |
| 58 | +- name: Removing k8s-master-nodes from /etc/hosts in the localhost if they already exist |
| 59 | + become: yes |
| 60 | + lineinfile: |
| 61 | + path: /etc/hosts |
| 62 | + regexp: ".*{{ item }}.*" |
| 63 | + state: absent |
| 64 | + loop: "{{ groups.k8s_master_nodes }}" |
| 65 | + |
| 66 | +- name: Adding k8s-master-nodes from /etc/hosts in the localhost |
| 67 | + become: yes |
| 68 | + lineinfile: |
| 69 | + path: /etc/hosts |
| 70 | + line: "{{ item.1 }} {{item.0}}" |
| 71 | + loop: "{{ groups.k8s_master_nodes|zip(k8s_master_nodes_ips)|list }}" |
| 72 | + |
| 73 | +- name: Removing k8s-worker-nodes from /etc/hosts in the localhost if they already exist |
| 74 | + become: yes |
| 75 | + lineinfile: |
| 76 | + path: /etc/hosts |
| 77 | + regexp: ".*{{ item }}.*" |
| 78 | + state: absent |
| 79 | + loop: "{{ groups.k8s_worker_nodes }}" |
| 80 | + |
| 81 | +- name: Adding k8s-worker-nodes to /etc/hosts in the localhost |
| 82 | + become: yes |
| 83 | + lineinfile: |
| 84 | + path: /etc/hosts |
| 85 | + line: "{{ item.1 }} {{item.0}}" |
| 86 | + loop: "{{ groups.k8s_worker_nodes|zip(k8s_worker_nodes_ips)|list }}" |
| 87 | + |
| 88 | +- name: Check if the ~/.ssh directory exists, if not create it |
| 89 | + file: |
| 90 | + path: "{{ ssh_key_path }}" |
| 91 | + state: directory |
| 92 | + mode: '0755' |
| 93 | + |
| 94 | +- name: Checking if ssh key exists and if not generate a new one |
| 95 | + openssh_keypair: |
| 96 | + path: "{{ ssh_key_path }}/{{ssh_key_name}}" |
| 97 | + |
| 98 | +- name: Run "vagrant up" with the Vagrantfile as input. |
| 99 | + command: vagrant up |
0 commit comments