这个问题在这里已有答案:
为了加快Ansible流程的目的,我只需要从主机中检索一些细节。我最常需要的信息是ansible_hostname,以确保我登陆正确的主机,因为我有一个动态DNS。在哪个gather_subset主机名下降?
可以使用gather_facts限制收集的信息。请查看ansible setup module的文档,了解如何根据各种子集限制信息。
- hosts: my_target
gather_facts:no
pre_tasks:
- setup:
gather_subset: 'network'
tasks:
- debug: var=ansible_hostname
可从中收集信息的可用子集如下
all,all_ipv4_addresses,all_ipv6_addresses,apparmor,architecture,caps,chroot,cmdline,date_time,default_ipv4,default_ipv6,devices,distribution,distribution_major_version,distribution_release,distribution_version,dns,effective_group_ids,effective_user_id,env,facter,fips,hardware,interfaces,is_chroot, kernel,local,lsb,machine,machine_id,mounts,network,ohai,os_family,pkg_mgr,platform,processor,processor_cores,processor_count,python,python_version,real_user_id,selinux,service_mgr,ssh_host_key_dsa_public,ssh_host_key_ecdsa_public,ssh_host_key_ed25519_public,ssh_host_key_rsa_public,ssh_host_pub_keys,ssh_pub_keys, system,system_capabilities,system_capabilities_enforced,user,user_dir,user_gecos,user_gid,user_id,user_shell,user_uid,virtual,virtualization_role,virtualization_type