| - name: Removing lxc default config |
| become: yes |
| file: |
| path: /etc/lxc/default.conf |
| state: absent |
| |
| - name: Copying default lxc file |
| become: yes |
| copy: |
| src: files/default.conf |
| dest: /etc/lxc/default.conf |
| mode: 644 |
| |
| - name: Creating lxc containers |
| lxc_container: |
| name: "{{ item.value.name }}" |
| container_log: true |
| template: ubuntu |
| state: started |
| template_options: --release "{{ item.value.release }}" |
| container_config: |
| - "lxc.network.ipv4={{ item.value.ip }}/24" |
| container_command: | |
| ln -s /usr/lib/jvm/java/bin/java /usr/bin/java |
| apt-get update |
| apt-get install -y openssh-server |
| useradd -s /bin/bash -m -p sakA7pjBdhIsE sdn |
| useradd sdn sudo |
| mkdir /home/sdn/.ssh |
| chown sdn.sdn /home/sdn/.ssh |
| echo "ubuntu ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-onos-sudoers |
| echo "sdn ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-onos-sudoers |
| with_dict: "{{ lxc }}" |
| |
| - name: Copying public key to containers |
| become: yes |
| copy: |
| src: "/home/ubuntu/.ssh/id_rsa.pub" |
| dest: "/var/lib/lxc/{{ item.value.name }}/rootfs/home/sdn/.ssh/authorized_keys" |
| mode: 600 |
| with_dict: "{{ lxc }}" |
| |
| - name: Setting owner and group on authorized key files |
| become: yes |
| shell: "lxc-attach --name {{ item.value.name }} -- chown sdn:sdn /home/sdn/.ssh/authorized_keys" |
| with_dict: "{{ lxc }}" |
| |
| - name: Setting permissions on authorized key files |
| become: yes |
| shell: "lxc-attach --name {{ item.value.name }} -- chmod 600 /home/sdn/.ssh/authorized_keys" |
| with_dict: "{{ lxc }}" |
| |
| - name: Disabling ssh strict host key checking |
| blockinfile: |
| dest: "/etc/ssh/ssh_config" |
| block: | |
| Host * |
| StrictHostKeyChecking no |
| |
| - name: Adding containers hostname to hosts file |
| lineinfile: |
| dest: /etc/hosts |
| regexp: "^{{ item.value.ip }}" |
| line: "{{ item.value.ip }} {{ item.value.name }}" |
| with_dict: "{{ lxc }}" |
| tags: [common] |