例如,如何限制Ansible的安装模块(gather_facts)仅检索服务器的主机名?=?

ww1*_*12z 1 ansible

严格来说,为了加快Ansible流程的速度,我只需要从主机中检索一些细节。我最需要的信息是ansible_hostname,以确保在拥有动态DNS时,我可以登陆正确的主机。主机名属于哪个collect_subset?

tux*_*tux 5

可以限制使用collect_facts收集的信息。请检查ansible设置模块的文档,以了解如何基于各种子集限制信息。

- hosts: my_target
  gather_facts:no

  pre_tasks:
    - setup:
        gather_subset: 'network'

  tasks:
    - debug: var=ansible_hostname
Run Code Online (Sandbox Code Playgroud)

可以从中收集信息的可用子集如下

所有,all_ipv4_addresses,all_ipv6_addresses,apparmor,体系结构,大写,chroot,cmdline,date_time,default_ipv4,default_ipv6,设备,分发,distribution_major_version,distribution_release,distribution_version,dns,effective_group_ids,effective_user_id,env,facter,fips,is内核,本地,lsb,计算机,machine_id,安装,网络,ohai,os_family,pkg_mgr,平台,处理器,处理器核心,处理器计数,python,python_version,real_user_id,selinux,service_mgr,ssh_host_key_dsa_public,ss_host_key_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_pub_s_host_key系统,system_capabilities,system_capabilities_enforced,用户,user_dir,user_gecos,user_gid,user_id,user_shell,user_uid,虚拟,virtualization_role,虚拟化类型