community.general icon indicating copy to clipboard operation
community.general copied to clipboard

proxmox: Usage of hookscripts

Open pelicangris opened this issue 3 years ago • 10 comments

Summary

I am trying to provision lxc containers via ansible and to have further ansible roles to configure the containers (add packages, etc...) however my first step would be to enable ssh on the containers. i figured i could use hookscripts on my newly created containers to install the ssh package and start the service but i am struggling to understand how to use this configuration token. i have tried to store a script on the proxmox server in one of my mounted volumes but i consistently get Creation of lxc VM 10001 failed with exception: 500 Internal Server Error: unable to parse directory volume name 'hooks/hook.sh'

This is the extract of my playbook, i figured that backups needs to be one of the volumes proxmox knows of but unsure:

- name: Create new container with default
  hosts: containers
  gather_facts: false

  tasks:
    - name:  Create Containers
      delegate_to: 127.0.0.1
      community.general.proxmox:
        node: proxmox
        proxmox_default_behavior: compatibility
        api_user: root@pam
        api_password: XXXXXXX
        api_host: XXXXXXX
        vmid: "{{vmid}}"
        memory: "{{ memory }}"
        cpus: "{{ cpus }}"
        hostname: "{{ inventory_hostname }}"
        pubkey: "ssh-rsa ..."
        password: testtest
        ostemplate: 'local:vztmpl/alpine-3.15-default_20211202_amd64.tar.xz'
        storage: local-lvm
        hookscript: 'backups:hooks/hook.sh`

Issue Type

Documentation Report

Component Name

community.general.proxmox

Ansible Version

$ ansible --version

ansible [core 2.11.12]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/<user>/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/<user>/.local/lib/python3.7/site-packages/ansible
  ansible collection location = /home/<user>/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/<user>/.local/bin/ansible
  python version = 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general

# /home/<user>/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 5.7.0

# /home/<user>/.local/lib/python3.7/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 3.8.3

Configuration

$ ansible-config dump --only-changed

OS / Environment

Debian

Additional Information

No response

Code of Conduct

  • [X] I agree to follow the Ansible Code of Conduct

pelicangris avatar Oct 04 '22 18:10 pelicangris

Files identified in the description: None

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot avatar Oct 04 '22 18:10 ansibullbot

!component community.general.proxmox

russoz avatar Oct 04 '22 22:10 russoz

Files identified in the description:

  • plugins/modules/cloud/misc/proxmox

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot avatar Oct 04 '22 22:10 ansibullbot

cc @Ajpantuso @Thulium-Drake @joshainglis @karmab @tleguern click here for bot help

ansibullbot avatar Oct 04 '22 22:10 ansibullbot

fwiw I finally got hook scripts working for myself. You might want to try changing the directory name from hook to snippets, this seems to be where PVE expects scripts to be, this might be the parsing issue you're facing.

morganrallen avatar Oct 06 '22 17:10 morganrallen

thanks! that's a good lead. do you happen to know where this 'snippets' directory needs to be on the proxmox host?

pelicangris avatar Oct 07 '22 07:10 pelicangris

nailed it! https://gist.github.com/aw/ce460c2100163c38734a83e09ac0439a

pelicangris avatar Oct 07 '22 07:10 pelicangris

Files identified in the description:

  • plugins/modules/proxmox

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot avatar Nov 08 '22 08:11 ansibullbot

cc @UnderGreen click here for bot help

ansibullbot avatar Jun 06 '23 07:06 ansibullbot

cc @krauthosting click here for bot help

ansibullbot avatar Feb 17 '24 11:02 ansibullbot