I'm starting with ansible. The main reason I'm looing into ansible vs other configuratoin management tools is its ability to orchestrate, that is to create programmatically, virtual machines on my virtualization environment. Currently proxmox-ve.
Here is what my first (proxmox-related) playbook looks like:
# Creates a host within proxmox environment
- hosts: localhost
tasks:
- name: "create vm"
proxmox:
node: cvirt
api_user: user@pve
api_password: password
api_host: 192.168.5.4
password: hostpass
hostname: ansiblehost1
storage: local-lvm
timeout: 300
ostemplate: 'local:vztmpl/centos-7-vagrant_amd64.tar.xz'
- name: "start vm"
proxmox:
node: cvirt
api_user: user@pve
api_password: password
api_host: 192.168.5.4
hostname: ansiblehost
state: started
Now, what annoys me with this playbook is that I have to repeat (over and over) the node, api_user, api_password, api_host options to every task I define.
What I would have liked to do was something along these lines:
# Defines options which will be inherited
- commonvariables:
node: cvirt
api_user: user@pve
api_password: password
api_host: 192.168.5.4
# Creates a host within proxmox environment
- hosts: localhost
tasks:
- name: "create vm"
proxmox:
inherits_options_from: commonvariables
hostname: ansiblehost1
storage: local-lvm
timeout: 300
ostemplate: 'local:vztmpl/centos-7-vagrant_amd64.tar.xz'
- name: "start vm"
proxmox:
inherits_options_from: commonvariables
hostname: ansiblehost
state: started
But I can't find anything that would allow me to do something like this.
I think I could do it with roles, Or I could do it with loops. But then what if I wanted to pass an extra option in some cases (netif, say)?
Any idea how I can achieve this 'options inheritance'?
In case it matters, I running: ansible 2.3.1.0