Ruby -根据条件更改值



如果默认值为target_vm,如何将hosts设置为对象的IP地址?如果默认值为"localhost",则"hosts"的值应该为"localhost"。

我正在尝试这样做…

hosts=> $evm.root['vm'].floating_ip_addresses if hosts == 'target_vm' else hosts,

下面是我要修改的函数:

def run_async(env_vars, extra_vars, playbook_path, hosts: ["localhost"], credentials: [], verbosity: 0, become_enabled: false)
run_via_cli(
hosts => $evm.root['vm'].floating_ip_addresses || hosts,
credentials,
env_vars,
extra_vars,
:ansible_runner_method => "start",
:playbook              => playbook_path,
:verbosity             => verbosity,
:become_enabled        => become_enabled
)
end

据我所知,您需要一行if-else语句。如果是这样的话,你可以这样做:

run_via_cli(hosts => hosts == 'target_vm' ? $evm.root['vm'].floating_ip_addresses : hosts)

相关内容

  • 没有找到相关文章

最新更新