Skip to content

Instantly share code, notes, and snippets.

@digilink
Created July 8, 2021 23:01
Show Gist options
  • Select an option

  • Save digilink/661cba6cca2461a07f6f3d05bca87500 to your computer and use it in GitHub Desktop.

Select an option

Save digilink/661cba6cca2461a07f6f3d05bca87500 to your computer and use it in GitHub Desktop.
Ansible Proxmox LXC deploy
---
- name: Proxmox lxc provision
hosts: pxsrv01
tasks:
- name: Create new container
proxmox:
vmid: '{{ vmid }}'
api_user: root@pam
api_token_id: root-ansible-token
api_token_secret: xxxxxxxxxxxxxxxxxxxxxx
api_host: pxsrv01
hostname: '{{ hostname }}'
node: pxsrv01
ostemplate: 'ISOS:vztmpl/debian-10-standard_10.7-1_amd64.tar.gz'
pubkey: "{{ lookup('file', '/Users/sbrown/code/ansible/keys/ansible_deploy.pub') }}"
memory: 1024
disk: '20'
storage: 'STORAGE'
netif: '{"net0":"name=eth0,ip=dhcp,bridge=vmbr0,tag=10"}'
- name: Start container
proxmox:
vmid: '{{ vmid }}'
api_user: root@pam
api_token_id: root-ansible-token
api_token_secret: xxxxxxxxxxxxxxx
api_host: pxsrv01
state: started
- name: Pause for 10 seconds to allow container to come online
pause:
seconds: 10
- name: Get container IP
shell: dig +noall +answer '{{ hostname }}'my.internal.net @10.0.10.254 | awk '{print $5}'
register: containerip
- name: Show container IP
debug:
var: containerip.stdout
---
- name: Proxmox container destroy
hosts: pxsrv01
tasks:
- name: Stop container with force
proxmox:
vmid: '{{ vmid }}'
api_user: root@pam
api_token_id: root-ansible-token
api_token_secret: xxxxxxxxxxxxxxxx
api_host: pxsrv01
force: yes
state: stopped
- name: Destroy container
proxmox:
vmid: '{{ vmid }}'
api_user: root@pam
api_token_id: root-ansible-token
api_token_secret: xxxxxxxxxxxxxxxxxx
api_host: pxsrv01
state: absent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment