首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >抗Xen供应

抗Xen供应
EN

Stack Overflow用户
提问于 2017-03-07 09:03:59
回答 1查看 2.6K关注 0票数 0

我昨天从Ansible开始,尝试在我的私有XenServer上提供VM。

我遵循了这个指南:XenGuide Sharknet.us

因此,我可以使用ansible的ping来重新缓存Xen服务器。

“我的项目”文件夹具有以下结构:

代码语言:javascript
复制
Project Folder
|-- site.yml
|-- hosts (inventory file)
+-+ host_vars
| |-- master01.lab.local
| |-- master02.lab.local
| |-- slave01.lab.local
| |-- slave02.lab.local
+-+ group_vars
| |-- all
+-+ roles
| +-+ master
| | |-- main.yml
| +-+ slave
| | |-- main.yml
| +-+ vm
| | |-- create_vm.yml
| | |-- main.yml

我的文件Site.yml:

代码语言:javascript
复制
[vm]
master01.lab.local
master02.lab.local
slave01.lab.local
slave02.lab.local

[hypervisor]
xen01.lab.local

host_vars/example 01.lab.local为例:

代码语言:javascript
复制
hostname: master01
ram: 8GiB
vcpus: 4

groups_vars/all文件:

代码语言:javascript
复制
centos_template_uid: 11fd3dc9-96cc-49af-b091-a2ca7e94c589
primary_sr_uid: 6e074a6e-bf19-031d-7c65-c9ab2749a3da
user_network_uid: 087af565-bd27-cd0a-93e4-724beeb27735

角色/vm/main.yml

代码语言:javascript
复制
 - name: Check if VM exists
   command: xe vm-list name-label={{ hostname }}
   register: found
   delegate_to: xen01.lab.local

 - include: create_vm.yml
   when: found.stdout == ""

 - name: Wait for the Kickstart install to complete and the VM to reboot
   local_action: wait_for host={{ hostname }}.lab.local port=22 delay=15 timeout=1200 state=started

角色/vm/create_vm.yml

代码语言:javascript
复制
- name: Prevent template from creating storage
  command: xe template-param-remove uuid={{ centos_template_uid }} param-name=other-config param-key=disks
  ignore_errors: yes
  delegate_to: xen01.lab.loca

- name: Create VM
  command: xe vm-install template={{ centos_template_uid }} new-name-label="{{ hostname }}" sr-uuid={{ primary_sr_uid }}
  register: vm
  delegate_to: xen01.lab.local

- name: Set the repository location
  command: xe vm-param-set uuid={{ vm.stdout }} other-config:install-repository="http://ansible-repo.lab.local/"
  delegate_to: xen01.lab.local

- name: Set the location of the kickstart file
  command: xe vm-param-set uuid={{ vm.stdout }} PV-args="ks=http://ansible-repo.lab.local/ks.cfg ksdevice=eth0"
  delegate_to: xen01.lab.local

- name: Assign a network
  command: xe vif-create vm-uuid={{ vm.stdout }} network-uuid={{ user_network_uid }} mac={{ mac }} device=0
  delegate_to: xen01.lab.local

- name: Allocate VM storage
  command: xe vdi-create name-label="{{ hostname }} storage" sr-uuid={{ primary_sr_uid }} type=system virtual-size=25GiB
  register: disk
  delegate_to: xen01.lab.local

- name: Assign storage to VM
command: xe vbd-create vdi-uuid={{ disk.stdout }} vm-uuid={{ vm.stdout }} type=Disk bootable=true device=0
delegate_to: xen01.lab.local

- name: Set the VM RAM limits
  command: xe vm-memory-limits-set vm={{ vm.stdout }} static-min={{ ram }} static-max={{ ram }} dynamic-min={{ ram }} dynamic-max={{ ram }}
  delegate_to: xen01.lab.local

- name: Set the number of CPUs
  command: xe vm-param-set VCPUs-max={{ vcpus }} uuid={{ vm.stdout }}
  delegate_to: xen01.lab.local

- name: Launch the VM
  command: xe vm-start uuid={{ vm.stdout }}
  delegate_to: xen01.lab.local

如果我现在运行以下命令:

代码语言:javascript
复制
ansible-playbook -i hosts site.yml -K

我得到以下错误:

代码语言:javascript
复制
ERROR! Syntax Error while loading YAML.

The error appears to have been in '/var/ansible/ansible-playbooks/provisioning/xen/roles/vm/tasks/main.yml': line 2, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:
- name: Check if VM exists
  command: xe vm-list name-label={{ hostname }}
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:

with_items:
  - {{ foo }}

Should be written as:

with_items:
  - "{{ foo }}"

有人知道这个错误吗?

EN

回答 1

Stack Overflow用户

发布于 2017-12-13 09:49:00

您应该引用字符串,包含变量,所以在您的情况下

代码语言:javascript
复制
command: xe vm-list name-label={{ hostname }}

应该变成

代码语言:javascript
复制
command: xe vm-list name-label="{{ hostname }}"

对于所有其他没有变量引号的任务也是如此。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42644083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档