我正在尝试配置我从模板构建的VyOS vm,该模板是一个新安装,没有任何配置。
vm没有配置IP,所以我不能使用ssh选项或vyos ansible模块。因此,我尝试使用vmware_vm_shell模块,它允许我执行命令,但不能进入VyOS的conf模式。
我尝试过bash和vbash作为我的外壳。我尝试过将conf命令设置为环境vars来执行,我已经尝试过with_item,但这似乎不适用于vmware_vm_shell。
我需要配置一个IP地址,这样我就可以使用ssh或者使用vyos模块来完成配置。
conf
set interfaces ethernet eth0 address 192.168.1.251/24
set service ssh port 22
commit
save---
- hosts: localhost
gather_facts: no
connection: local
vars:
vcenter_hostname: "192.168.1.100"
vcenter_username: "administrator@vsphere.local"
vcenter_password: "SekretPassword!"
datacenter: "Datacenter"
cluster: "Cluster"
vm_name: "router-01"
tasks:
- name: Run command inside a virtual machine
vmware_vm_shell:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ datacenter }}"
validate_certs: False
vm_id: "{{ vm_name }}"
vm_username: 'vyos'
vm_password: 'abc123!!!'
vm_shell: /bin/vbash
vm_shell_args: 'conf 2> myFile'
vm_shell_cwd: "/tmp"
delegate_to: localhost
register: shell_command_output这会引发错误:
/bin/vbash: conf: No such file or directory发布于 2020-08-30 22:49:30
我有一个EdgeRouter,它使用Vyatta派生的操作系统.您所遇到的问题是由于conf (或我的configure )实际上不是命令的名称造成的。cli特性是通过一个复杂的bash函数集合实现的,这些函数在非交互登录时没有加载。
有一个vyos.net上的wiki页面,它提出了解决方案。通过/opt/vyatta/etc/functions/script-template中的资源,您可以准备shell环境,这样vyos命令就可以像预期的那样工作了。
也就是说,您需要执行一个shell脚本(使用vbash),如下所示:
source /opt/vyatta/etc/functions/script-template
conf
set interfaces ethernet eth0 address 192.168.1.251/24
set service ssh port 22
commit
save
exit我不熟悉vmware_vm_shell模块,因此我不知道您将如何做到这一点,但是,例如,对于我来说,运行一个命令是可行的:
ssh ubnt@router 'vbash -c "source /opt/vyatta/etc/functions/script-template
configure
show interfaces
"'注意上面的换行符。这表明这可能有效:
- name: Run command inside a virtual machine
vmware_vm_shell:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ datacenter }}"
validate_certs: False
vm_id: "{{ vm_name }}"
vm_username: 'vyos'
vm_password: 'abc123!!!'
vm_shell: /bin/vbash
vm_shell_cwd: "/tmp"
vm_shell_args: |-
-c "source /opt/vyatta/etc/functions/script-template
configure
set interfaces ethernet eth0 address 192.168.1.251/24
set service ssh port 22
commit
save"
delegate_to: localhost
register: shell_command_outputhttps://stackoverflow.com/questions/63662290
复制相似问题