blob: a62c7c4a4d047cd41dc1c7884eb0491f3c607639 [file] [log] [blame]
Luca Prete8d4e8bc2016-08-24 14:49:54 -07001- name: Removing lxc default config
alshabib4997cd72016-05-24 22:48:29 -07002 become: yes
Luca Prete8d4e8bc2016-08-24 14:49:54 -07003 file:
4 path: /etc/lxc/default.conf
5 state: absent
alshabib4997cd72016-05-24 22:48:29 -07006
Luca Prete8d4e8bc2016-08-24 14:49:54 -07007- name: Copying default lxc file
alshabib4997cd72016-05-24 22:48:29 -07008 become: yes
9 copy:
10 src: files/default.conf
11 dest: /etc/lxc/default.conf
12 mode: 644
13
Luca Prete8d4e8bc2016-08-24 14:49:54 -070014- name: Creating lxc containers
alshabib4997cd72016-05-24 22:48:29 -070015 lxc_container:
Luca Prete8d4e8bc2016-08-24 14:49:54 -070016 name: "{{ item.value.name }}"
alshabib4997cd72016-05-24 22:48:29 -070017 container_log: true
18 template: ubuntu
19 state: started
Luca Prete8d4e8bc2016-08-24 14:49:54 -070020 template_options: --release "{{ item.value.release }}"
alshabib4997cd72016-05-24 22:48:29 -070021 container_config:
Luca Prete8d4e8bc2016-08-24 14:49:54 -070022 - "lxc.network.ipv4={{ item.value.ip }}/24"
alshabibbdb7b372016-05-25 09:46:49 -070023 container_command: |
24 ln -s /usr/lib/jvm/java/bin/java /usr/bin/java
alshabib4997cd72016-05-24 22:48:29 -070025 apt-get update
26 apt-get install -y openssh-server
Luca Prete8d4e8bc2016-08-24 14:49:54 -070027 useradd -s /bin/bash -m -p sakA7pjBdhIsE sdn
28 useradd sdn sudo
29 mkdir /home/sdn/.ssh
30 chown sdn.sdn /home/sdn/.ssh
alshabib4997cd72016-05-24 22:48:29 -070031 echo "ubuntu ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-onos-sudoers
Luca Prete8d4e8bc2016-08-24 14:49:54 -070032 echo "sdn ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-onos-sudoers
33 with_dict: "{{ lxc }}"
alshabib4997cd72016-05-24 22:48:29 -070034
Luca Prete8d4e8bc2016-08-24 14:49:54 -070035- 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 }}"
alshabib4997cd72016-05-24 22:48:29 -070042
Luca Prete8d4e8bc2016-08-24 14:49:54 -070043- 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]