Created
June 11, 2017 10:18
-
-
Save KeyboardInterrupt/18f53e2a62688db80011f0a835e90ecc to your computer and use it in GitHub Desktop.
lxd_deploy.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: localhost | |
become: no | |
connection: local | |
vars: | |
action: build | |
image: ubuntu/xenial/amd64 | |
user: ubuntu | |
pubkey_file: "{{ ansible_env.HOME}}/.ssh/id_rsa.pub" | |
machines: | |
- moep-fs00 | |
- moep-fs01 | |
tasks: | |
- name: Delete lxd container | |
lxd_container: | |
name: "{{ item }}" | |
state: absent | |
with_items: | |
"{{ machines }}" | |
register: delete_information | |
when: action == "delete" | |
- name: Create lxd container | |
lxd_container: | |
name: "{{ item }}" | |
state: started | |
source: | |
type: image | |
mode: pull | |
server: https://images.linuxcontainers.org | |
protocol: lxd | |
alias: "{{ image }}" | |
profiles: ["default"] | |
key_file: /home/christian/.ssh/id_rsa.pub | |
wait_for_ipv4_addresses: true | |
timeout: 600 | |
register: lxd_containers | |
with_items: | |
"{{machines}}" | |
when: action == "build" | |
- name: configure lxd container | |
shell: | | |
ssh-keygen -f "$HOME/.ssh/known_hosts" -R {{ item }}.lxd | |
lxc exec {{ item }} -- apt install python openssh-server -y | |
lxc exec {{ item }} -- bash -c 'echo "{{ user }} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/{{ user }}' | |
lxc exec {{ item }} -- mkdir -p /home/{{ user }}/.ssh | |
lxc file push {{ pubkey_file }} {{ item }}/home/{{ user }}/.ssh/authorized_keys | |
lxc exec {{ item }} -- chown -R ubuntu. /home/{{ user }}/.ssh | |
lxc snapshot {{ item }} init | |
with_items: "{{machines}}" | |
when: action == "build" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment