Skip to content

Instantly share code, notes, and snippets.

@KeyboardInterrupt
Created June 11, 2017 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KeyboardInterrupt/18f53e2a62688db80011f0a835e90ecc to your computer and use it in GitHub Desktop.
Save KeyboardInterrupt/18f53e2a62688db80011f0a835e90ecc to your computer and use it in GitHub Desktop.
lxd_deploy.yml
- 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