Question:
I see that Ansible provide some pre-defined variables that we can use in playbooks and template files. For example, the host IP address is ansible_eth0.ipv4.address
. Googleing and searching the docs I couldn’t find a list of all available variables.
Would someone list them for me?
Answer:
From the FAQ:
How do I see a list of all of the ansible_ variables?
Ansible by default gathers “facts” about the machines under management, and these facts can be accessed in playbooks and in templates. To see a list of all of the facts that are available about a machine, you can run the
setup
module as an ad hoc action:
12 ansible -m setup hostnameThis will print out a dictionary of all of the facts that are available for that particular host. You might want to pipe the output to a pager.This does NOT include inventory variables or internal ‘magic’ variables. See the next question if you need more than just ‘facts’.
Here is the output for my vagrant virtual machine called scdev
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
scdev | success >> { "ansible_facts": { "ansible_all_ipv4_addresses": [ "10.0.2.15", "192.168.10.10" ], "ansible_all_ipv6_addresses": [ "fe80::a00:27ff:fe12:9698", "fe80::a00:27ff:fe74:1330" ], "ansible_architecture": "i386", "ansible_bios_date": "12/01/2006", "ansible_bios_version": "VirtualBox", "ansible_cmdline": { "BOOT_IMAGE": "/vmlinuz-3.2.0-23-generic-pae", "quiet": true, "ro": true, "root": "/dev/mapper/precise32-root" }, "ansible_date_time": { "date": "2013-09-17", "day": "17", "epoch": "1379378304", "hour": "00", "iso8601": "2013-09-17T00:38:24Z", "iso8601_micro": "2013-09-17T00:38:24.425092Z", "minute": "38", "month": "09", "second": "24", "time": "00:38:24", "tz": "UTC", "year": "2013" }, "ansible_default_ipv4": { "address": "10.0.2.15", "alias": "eth0", "gateway": "10.0.2.2", "interface": "eth0", "macaddress": "08:00:27:12:96:98", "mtu": 1500, "netmask": "255.255.255.0", "network": "10.0.2.0", "type": "ether" }, "ansible_default_ipv6": {}, "ansible_devices": { "sda": { "holders": [], "host": "SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode] (rev 02)", "model": "VBOX HARDDISK", "partitions": { "sda1": { "sectors": "497664", "sectorsize": 512, "size": "243.00 MB", "start": "2048" }, "sda2": { "sectors": "2", "sectorsize": 512, "size": "1.00 KB", "start": "501758" }, }, "removable": "0", "rotational": "1", "scheduler_mode": "cfq", "sectors": "167772160", "sectorsize": "512", "size": "80.00 GB", "support_discard": "0", "vendor": "ATA" }, "sr0": { "holders": [], "host": "IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)", "model": "CD-ROM", "partitions": {}, "removable": "1", "rotational": "1", "scheduler_mode": "cfq", "sectors": "2097151", "sectorsize": "512", "size": "1024.00 MB", "support_discard": "0", "vendor": "VBOX" }, "sr1": { "holders": [], "host": "IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)", "model": "CD-ROM", "partitions": {}, "removable": "1", "rotational": "1", "scheduler_mode": "cfq", "sectors": "2097151", "sectorsize": "512", "size": "1024.00 MB", "support_discard": "0", "vendor": "VBOX" } }, "ansible_distribution": "Ubuntu", "ansible_distribution_release": "precise", "ansible_distribution_version": "12.04", "ansible_domain": "", "ansible_eth0": { "active": true, "device": "eth0", "ipv4": { "address": "10.0.2.15", "netmask": "255.255.255.0", "network": "10.0.2.0" }, "ipv6": [ { "address": "fe80::a00:27ff:fe12:9698", "prefix": "64", "scope": "link" } ], "macaddress": "08:00:27:12:96:98", "module": "e1000", "mtu": 1500, "type": "ether" }, "ansible_eth1": { "active": true, "device": "eth1", "ipv4": { "address": "192.168.10.10", "netmask": "255.255.255.0", "network": "192.168.10.0" }, "ipv6": [ { "address": "fe80::a00:27ff:fe74:1330", "prefix": "64", "scope": "link" } ], "macaddress": "08:00:27:74:13:30", "module": "e1000", "mtu": 1500, "type": "ether" }, "ansible_form_factor": "Other", "ansible_fqdn": "scdev", "ansible_hostname": "scdev", "ansible_interfaces": [ "lo", "eth1", "eth0" ], "ansible_kernel": "3.2.0-23-generic-pae", "ansible_lo": { "active": true, "device": "lo", "ipv4": { "address": "127.0.0.1", "netmask": "255.0.0.0", "network": "127.0.0.0" }, "ipv6": [ { "address": "::1", "prefix": "128", "scope": "host" } ], "mtu": 16436, "type": "loopback" }, "ansible_lsb": { "codename": "precise", "description": "Ubuntu 12.04 LTS", "id": "Ubuntu", "major_release": "12", "release": "12.04" }, "ansible_machine": "i686", "ansible_memfree_mb": 23, "ansible_memtotal_mb": 369, "ansible_mounts": [ { "device": "/dev/mapper/precise32-root", "fstype": "ext4", "mount": "/", "options": "rw,errors=remount-ro", "size_available": 77685088256, "size_total": 84696281088 }, { "device": "/dev/sda1", "fstype": "ext2", "mount": "/boot", "options": "rw", "size_available": 201044992, "size_total": 238787584 }, { "device": "/vagrant", "fstype": "vboxsf", "mount": "/vagrant", "options": "uid=1000,gid=1000,rw", "size_available": 42013151232, "size_total": 484145360896 } ], "ansible_os_family": "Debian", "ansible_pkg_mgr": "apt", "ansible_processor": [ "Pentium(R) Dual-Core CPU E5300 @ 2.60GHz" ], "ansible_processor_cores": "NA", "ansible_processor_count": 1, "ansible_product_name": "VirtualBox", "ansible_product_serial": "NA", "ansible_product_uuid": "NA", "ansible_product_version": "1.2", "ansible_python_version": "2.7.3", "ansible_selinux": false, "ansible_swapfree_mb": 766, "ansible_swaptotal_mb": 767, "ansible_system": "Linux", "ansible_system_vendor": "innotek GmbH", "ansible_user_id": "neves", "ansible_userspace_architecture": "i386", "ansible_userspace_bits": "32", "ansible_virtualization_role": "guest", "ansible_virtualization_type": "virtualbox" }, "changed": false } |
The current documentation now has a complete chapter about Discovering variables: facts and magic variables.