我试图在Ansible中运行这个剧本,但是它抱怨变量ansible_memtotal_mb是未定义的。这是对我来说失败的剧本。
- hosts: all
gather_facts: yes
tasks:
- debug:
msg: "{{ ansible_memtotal_mb }}"尽管gather_facts在剧中被设定为yes。
经过更多的调查,我发现我可以在我的目标主机上看到使用ansible host -m setup的事实,但它在剧本中还没有定义。
我正在使用ansible-core 2.12.1。下面是关于目标操作系统的一些信息:
Linux serverName 5.11.0-1025-aws #27~20.04.1-Ubuntu SMP Fri Jan 7 13:09:56 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux目标机器是Ubuntu的AWS EC2实例。
收集到的事实
- hosts: all
gather_facts: yes
tasks:
- debug:
msg: "{{ ansible_facts }}"仅限
{'cmdline': {'BOOT_IMAGE': '/boot/vmlinuz-5.11.0-1025-aws', 'root': 'PARTUUID=24ca9e81-01', 'ro': True, 'console': 'ttyS0', 'nvme_core.io_timeout': '4294967295', 'panic': '-1'}, 'proc_cmdline': {'BOOT_IMAGE': '/boot/vmlinuz-5.11.0-1025-aws', 'root': 'PARTUUID=24ca9e81-01', 'ro': True, 'console': ['tty1', 'ttyS0'], 'nvme_core.io_timeout': '4294967295', 'panic': '-1'}, 'dns': {'nameservers': ['127.0.0.1'], 'search': ['us-west-2.compute.internal', 'node.ca1.consul', 'node.us1.consul']}, 'selinux_python_present': True, 'selinux': {'status': 'disabled'},
'lsb': {'id': 'Ubuntu', 'description': 'Ubuntu 20.04.3 LTS', 'release': '20.04', 'codename': 'focal', 'major_release': '20'}, 'system_capabilities_enforced': 'True', 'system_capabilities': [''], 'distribution': 'Ubuntu', 'distribution_release': 'focal', 'distribution_version': '20.04', 'distribution_major_version': '20', 'distribution_file_path': '/etc/os-release', 'distribution_file_variety': 'Debian', 'distribution_file_parsed': True, 'os_family': 'Debian', 'ansible_local': {}, 'fips': False, 'apparmor': {'status': 'enabled'}, 'python': {'version': {'major': 3, 'minor': 8, 'micro': 10, 'releaselevel': 'final', 'serial': 0}, 'version_info': [3, 8, 10, 'final', 0], 'executable': '/usr/bin/python3.8', 'has_sslcontext': True, 'type': 'cpython'}, 'system': 'Linux', 'kernel': '5.11.0-1025-aws', 'kernel_version': '#27~20.04.1-Ubuntu SMP Fri Jan 7 13:09:56 UTC 2022', 'machine': 'x86_64', 'python_version': '3.8.10', 'fqdn': 'private', 'hostname': 'private', 'nodename': 'private', 'domain': '', 'userspace_bits': '64', 'architecture': 'x86_64', 'userspace_architecture': 'x86_64', 'machine_id': 'private', 'pkg_mgr': 'apt', 'service_mgr': 'systemd', 'gather_subset': ['!hardware'], 'module_setup': True}`但根据不可信事实的说法,人们期望看到的情况如下
"ansible_memfree_mb": 7709,
"ansible_memory_mb": {
"nocache": {
"free": 7804,
"used": 173
},
"real": {
"free": 7709,
"total": 7977,
"used": 268
},
"swap": {
"cached": 0,
"free": 0,
"total": 0,
"used": 0
}
},
"ansible_memtotal_mb": 7977,请您提供有关这个奇怪问题的任何信息,我们都欢迎。
发布于 2022-01-21 20:01:15
经过一些调查收集到的事实和发现
"gather_subset": [
"!hardware"
],
"module_setup": true
}原来,在参数文件中有一个ansible.cfg设置为
gather_subset = !hardware这使得Ansible无法默认地收集内存信息,因为memory_facts是hardware_facts (根据实用程序/事实/硬件/linux.py )。
删除配置行将Ansible返回到其默认行为。
https://stackoverflow.com/questions/70777188
复制相似问题