Luca Prete | 8d4e8bc | 2016-08-24 14:49:54 -0700 | [diff] [blame] | 1 | - name: Removing lxc default config |
alshabib | 4997cd7 | 2016-05-24 22:48:29 -0700 | [diff] [blame] | 2 | become: yes |
Luca Prete | 8d4e8bc | 2016-08-24 14:49:54 -0700 | [diff] [blame] | 3 | file: |
| 4 | path: /etc/lxc/default.conf |
| 5 | state: absent |
alshabib | 4997cd7 | 2016-05-24 22:48:29 -0700 | [diff] [blame] | 6 | |
Luca Prete | 8d4e8bc | 2016-08-24 14:49:54 -0700 | [diff] [blame] | 7 | - name: Copying default lxc file |
alshabib | 4997cd7 | 2016-05-24 22:48:29 -0700 | [diff] [blame] | 8 | become: yes |
| 9 | copy: |
| 10 | src: files/default.conf |
| 11 | dest: /etc/lxc/default.conf |
| 12 | mode: 644 |
| 13 | |
Luca Prete | 8d4e8bc | 2016-08-24 14:49:54 -0700 | [diff] [blame] | 14 | - name: Creating lxc containers |
alshabib | 4997cd7 | 2016-05-24 22:48:29 -0700 | [diff] [blame] | 15 | lxc_container: |
Luca Prete | 8d4e8bc | 2016-08-24 14:49:54 -0700 | [diff] [blame] | 16 | name: "{{ item.value.name }}" |
alshabib | 4997cd7 | 2016-05-24 22:48:29 -0700 | [diff] [blame] | 17 | container_log: true |
| 18 | template: ubuntu |
| 19 | state: started |
Luca Prete | 8d4e8bc | 2016-08-24 14:49:54 -0700 | [diff] [blame] | 20 | template_options: --release "{{ item.value.release }}" |
alshabib | 4997cd7 | 2016-05-24 22:48:29 -0700 | [diff] [blame] | 21 | container_config: |
Luca Prete | 8d4e8bc | 2016-08-24 14:49:54 -0700 | [diff] [blame] | 22 | - "lxc.network.ipv4={{ item.value.ip }}/24" |
alshabib | bdb7b37 | 2016-05-25 09:46:49 -0700 | [diff] [blame] | 23 | container_command: | |
| 24 | ln -s /usr/lib/jvm/java/bin/java /usr/bin/java |
alshabib | 4997cd7 | 2016-05-24 22:48:29 -0700 | [diff] [blame] | 25 | apt-get update |
| 26 | apt-get install -y openssh-server |
Luca Prete | 8d4e8bc | 2016-08-24 14:49:54 -0700 | [diff] [blame] | 27 | useradd -s /bin/bash -m -p sakA7pjBdhIsE sdn |
| 28 | useradd sdn sudo |
| 29 | mkdir /home/sdn/.ssh |
| 30 | chown sdn.sdn /home/sdn/.ssh |
alshabib | 4997cd7 | 2016-05-24 22:48:29 -0700 | [diff] [blame] | 31 | echo "ubuntu ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-onos-sudoers |
Luca Prete | 8d4e8bc | 2016-08-24 14:49:54 -0700 | [diff] [blame] | 32 | echo "sdn ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-onos-sudoers |
| 33 | with_dict: "{{ lxc }}" |
alshabib | 4997cd7 | 2016-05-24 22:48:29 -0700 | [diff] [blame] | 34 | |
Luca Prete | 8d4e8bc | 2016-08-24 14:49:54 -0700 | [diff] [blame] | 35 | - name: Copying public key to containers |
| 36 | become: yes |
| 37 | copy: |
| 38 | src: "/home/ubuntu/.ssh/id_rsa.pub" |
| 39 | dest: "/var/lib/lxc/{{ item.value.name }}/rootfs/home/sdn/.ssh/authorized_keys" |
| 40 | mode: 600 |
| 41 | with_dict: "{{ lxc }}" |
alshabib | 4997cd7 | 2016-05-24 22:48:29 -0700 | [diff] [blame] | 42 | |
Luca Prete | 8d4e8bc | 2016-08-24 14:49:54 -0700 | [diff] [blame] | 43 | - name: Setting owner and group on authorized key files |
| 44 | become: yes |
| 45 | shell: "lxc-attach --name {{ item.value.name }} -- chown sdn:sdn /home/sdn/.ssh/authorized_keys" |
| 46 | with_dict: "{{ lxc }}" |
| 47 | |
| 48 | - name: Setting permissions on authorized key files |
| 49 | become: yes |
| 50 | shell: "lxc-attach --name {{ item.value.name }} -- chmod 600 /home/sdn/.ssh/authorized_keys" |
| 51 | with_dict: "{{ lxc }}" |
| 52 | |
| 53 | - name: Disabling ssh strict host key checking |
| 54 | blockinfile: |
| 55 | dest: "/etc/ssh/ssh_config" |
| 56 | block: | |
| 57 | Host * |
| 58 | StrictHostKeyChecking no |
| 59 | |
| 60 | - name: Adding containers hostname to hosts file |
| 61 | lineinfile: |
| 62 | dest: /etc/hosts |
| 63 | regexp: "^{{ item.value.ip }}" |
| 64 | line: "{{ item.value.ip }} {{ item.value.name }}" |
| 65 | with_dict: "{{ lxc }}" |
| 66 | tags: [common] |