尝试在 ansible 中创建新虚拟机时出错 [英] Error trying to create a new vm in ansible

查看:24
本文介绍了尝试在 ansible 中创建新虚拟机时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习 Ansible.到目前为止一直很痛苦.我有这个代码来创建一个新的虚拟机.我遵循了这个教程.

I just started learning Ansible. It has been a pain so far. I have this code to create a new vm. I followed this tutorial.

 ---
- hosts: localhost
  connection: local
  tasks:
    - vsphere_guest:
            vcenter_hostname:1.1.1.12
            username: root
            password: pasword
            guest: newvm001
            state: powered_on
            validate_certs: no
            vm_extra_config:
                vcpu.hotadd: yes
                mem.hotadd:  yes
                notes: This is a test VM
                folder: MyFolder
            vm_disk:
                disk1:
                        size_gb: 10
                        type: thin
                        datastore: storage001
            vm_nic:
                nic1:
                    type: vmxnet3
                    network: VM Network
                    network_type: standard
            vm_hardware:
                memory_mb: 256
                num_cpus: 1
                osid: ubuntu64Guest
                scsi: paravirtual
            esxi:
                datacenter: 1.1.1.12
                hostname: 1.1.1.12

但是我一直收到这个错误.

I however keep getting this error.

[警告]:找不到主机文件:/etc/ansible/hosts

[WARNING]: Host file not found: /etc/ansible/hosts

[警告]:提供的主机列表为空,只有本地主机可用

[WARNING]: provided hosts list is empty, only localhost is available

播放 [本地主机]

任务 [设置]*********************************************************************** 好的:[本地主机]

TASK [setup] ******************************************************************* ok: [localhost]

任务 [vsphere_guest]*************************************************************** 致命:[本地主机]:失败!=>{已更改":假,失败":真,味精":找不到名为:9.1.142.86 的数据中心"}

TASK [vsphere_guest] *********************************************************** fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Cannot find datacenter named: 9.1.142.86"}

没有更多的主机了***************************************************************** [警告]:无法创建重试文件testing.retry".[错误2] 没有这样的文件或目录:''

NO MORE HOSTS LEFT ************************************************************* [WARNING]: Could not create retry file 'testing.retry'. [Errno 2] No such file or directory: ''

播放回顾************************************************************************* 本地主机:ok=1 已更改=0 无法访问=0
失败=1

PLAY RECAP ********************************************************************* localhost : ok=1 changed=0 unreachable=0
failed=1

为什么会这样?主机文件和清单文件有什么区别?

Why is that so? And what is the difference between a host file and an inventory file?

推荐答案

主机文件和清单文件有什么区别?

what is the difference between a host file and an inventory file?

它们是一样的.但是,由于您在本地计算机上执行所有操作,因此您只有 localhost 可用.

They are the same. However, since you're doing everything on your local machine, it's fine that you only have localhost available.

这是你的错误:

任务 [vsphere_guest] *************************************************************** 致命:[本地主机]:失败!=>{changed":false,failed":true,msg":无法找到名为:9.1.142.86"的数据中心}

TASK [vsphere_guest] *********************************************************** fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Cannot find datacenter named: 9.1.142.86"}

我不清楚你为什么会收到你提供的剧本,因为它根本没有提到那个 IP,我怀疑导致问题的线路是

It's not clear to me why you're receiving this with the playbook you've provided, as it doesn't mention that IP at all and the line I suspect is causing the problem is

datacenter: 1.1.1.12

您确定这是您正在运行的文件,并且您已保存对其所做的任何更改吗?

Are you sure this is the file you're running, and that you've saved any changes you've made to it?

这篇关于尝试在 ansible 中创建新虚拟机时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆