我想使用ansible setup模块在for循环中检索主机规范。
规格:

declare -a specs=("ansible_all_ipv4_addresses" "ansible_processor" "ansible_processor_cores" "ansible_uptime_seconds")

对于循环:
for i in "${specs[@]}"
do
    ansible rhelmachines -m setup -a 'filter='$i'
done

如何仅在一个连接中连接多个筛选器?
谢谢!

最佳答案

specs=( "ansible_all_ipv4_addresses"
        "ansible_processor"
        "ansible_processor_cores"
        "ansible_uptime_seconds" )
args=( )
for spec in "${specs[@]}"; do args+=( -a "$spec" ); done
ansible rhelmachines -m setup "${args[@]}"

…将导致您的最终命令等同于:
ansible rhelmachines -m setup \
  -a ansible_all_ipv4_addresses \
  -a ansible_processor \
  -a ansible_processor_cores \
  -a ansible_uptime_seconds

关于linux - 如何在Ansible设置命令中放置多个过滤器参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51038279/

10-10 07:37