[SOLVED] ansible-playbook create vm on proxmox

rogu

New Member
May 21, 2024
5
0
1
So its 2024...
and im trying to create a vm thru ansibleplaybooks.

I'm looking for some what simple and "dumb" code that creates an VM from a template....
And btw how does ansible playbooks work with vmids? do i have to edit the playbook everytime i run it with a new vmid?

this code is the closest ive come sofar..
YAML:
---
- name: Create Virtual Machine
  tasks:
    - proxmox_kvm:
      api_host: 192.168.100.100
      api_user: root@pam
      api_token_id: TOKEN ID
      api_token_secret: TOKEN SECRET
      name: mc-serv
      node: pve6
      newid: 800
      clone: MC-server
      storage: VM-Storage
      state: present

Im running this code and getting the return:

Code:
[user]: ansible-playbook test4.yaml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
ERROR! 'community.general.proxmox_kvm' is not a valid attribute for a Play

The error appears to be in '/home/admin/vm/test4.yaml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Create Virtual Machine
  ^ here

[Edit]
solution was change the structor,
Im currently using something simular to this
https://www.reddit.com/r/ansible/comments/12bbynr/proxmox_ansible_and_vm_templates/
 
Last edited:
Hello,

Note that the problem you have is an Ansible problem, it is not Proxmox specific.

As the error message tells you, you didn't specify any inventory.
You need to create one, then re-run your playbook against it :
$ ansible-playbook my_nice_playbook.yml -i my_nice_inventory
Also, ansible advises you to correct your yaml syntax.
Try beginning with:
Code:
---

- hosts: all

  tasks:

    - name: Create KVM Virtual Machines

      ...


You will find further appropriate help on : https://docs.ansible.com/

Kind regards,

GD
 
Last edited:
Hello,

Note that the problem you have is an Ansible problem, it is not Proxmox specific.

As the error message tells you, you didn't specify any inventory.
You need to create one, then re-run your playbook against it :
$ ansible-playbook my_nice_playbook.yml -i my_nice_inventory
Also, ansible advises you to correct your yaml syntax.
Try beginning with:
Code:
---

- hosts: all

  tasks:

    - name: Create KVM Virtual Machines

      ...


You will find further appropriate help on : https://docs.ansible.com/

Kind regards,

GD
Thx! Ill try this and come back with results successful or not :D
 
Unforunetly this does not work. Ive been busy with other stuff and now returned to this.

the error message is as follow:
Code:
mcadmin@lu-cntl-srv:/etc/ansible$ ansible-playbook -i mcsrv, playbook/test5.yml
ERROR! no module/action detected in task.

The error appears to be in '/etc/ansible/playbook/test5.yml': line 4, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  tasks:
    - name: Create Virtual Machine
      ^ here

This is the internal playbook:

YAML:
---
- hosts: all
  tasks:
    - name: Create Virtual Machine
    - proxmox_kvm:
      api_host: 192.168.100.106
      api_user: root@pam
      api_token_id: (ID)
      api_token_secret: (SECRET)
      name: mc-serv
      node: pve6
      newid: 800
      clone: MC-server
      storage: VM-Storage
      state: present

any insights?

(edit)

ive also asked in ansible forums but they are not as fast responding and ive been waiting for a reply for over 7 hours
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!