Redis can make Ansible only a bit faster
Tags: ansible, redis
Published: 2019-11-09 14:27:26

Ansible has a function called "Gather Facts" which retrieves variables from target hosts.
By default, the facts are cached in memory and gathered every time you run Playbook.
Usually, it takes only a few seconds but I know some people get annoyed by it.

So in this post, I will try to avoid the struggles with Redis instead of memory.


## Environment

Local Machine: MacOS Mojave 10.14.5
Target Host: CentOS 7.5 on Vagrant
Ansible: 2.8.1
Redis: 5.0.5

### Redis

It is only a test so I am using docker.

```
[koh@kohs-MBP] ~/vag_test
% docker run -d -p 6379:6379 --name ansibleredis redis
Unable to find image 'redis:latest' locally
latest: Pulling from library/redis
f5d23c7fed46: Pull complete
a4a5c04dafc1: Pull complete
605bafc84bc9: Pull complete
f07a4e35cd96: Pull complete
17944e5e3eb7: Pull complete
6f875a8605e0: Pull complete
Digest: sha256:8888f6cd2509062a377e903e17777b4a6d59c92769f6807f034fa345da9eebcf
Status: Downloaded newer image for redis:latest
cbb0b15a703b2044b8a3d0d7b5b58f6dbd8d0b09d7b16bb5560cec57a221c39e
[koh@kohs-MBP] ~/vag_test
% docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
cbb0b15a703b        redis               "docker-entrypoint.s…"   8 seconds ago       Up 7 seconds        0.0.0.0:6379->6379/tcp   ansibleredis
[koh@kohs-MBP] ~/vag_test
%
```

Done. Docker is awesome as you know.  

### Ansible

Using the official document as a reference, I added the below entries to ansible.cfg.
https://docs.ansible.com/ansible/latest/plugins/cache.html

```
[koh@kohs-MBP] ~/vag_test
% cat ansible.cfg
[defaults]

# Specify cache plugin
fact_caching = redis
# Prefix of key name
fact_caching_prefix = ansible_facts_
# Connection info of Redis(host:port)
fact_caching_connection = localhost:6379
# timeout until cache expire(s)
fact_caching_timeout = 60
# Policy of using cache. smart: if valid cache exists, Ansible would use.
gathering = smart
[koh@kohs-MBP] ~/vag_test
%
```
I set timeout short for testing. Please set it as you like.

### Playbook

I prepared the below simple Playbook.
After gather\_facts, prints ansible\_hostname.

```
[koh@kohs-MBP] ~/vag_test
% cat test.yml
---
- hosts: Vag1
  gather_facts: True
  tasks:
    - name: debug
      debug:
        var: ansible_hostname
[koh@kohs-MBP] ~/vag_test
%
```

## Test

### Default(memory)

First, I commented out all fact_caching_foobar lines. Then check the time with time command.

```
[koh@kohs-MBP] ~/vag_test
% time ansible-playbook test.yml

PLAY [Vag1] *****************************************************************************************

TASK [Gathering Facts] ******************************************************************************
ok: [Vag1]

TASK [debug] ****************************************************************************************
ok: [Vag1] => {
    "ansible_hostname": "Vag1"
}

PLAY RECAP ******************************************************************************************
Vag1                       : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

ansible-playbook test.yml  1.02s user 0.30s system 67% cpu 1.955 total
[koh@kohs-MBP] ~/vag_test
%
```
It took about 2 seconds.
I tested multiple times but it takes about 1.8 to 2.0 seconds.

### Redis

Now enabled fact_caching_foobar lines in ansible.cfg and check time.

```
[koh@kohs-MBP] ~/vag_test
% cat ansible.cfg
[defaults]

# Specify cache plugin
fact_caching = redis
# Prefix of key name
fact_caching_prefix = ansible_facts_
# Connection info of Redis(host:port)
fact_caching_connection = localhost:6379
# timeout until cache expire(s)
fact_caching_timeout = 60
# Policy of using cache. smart: if valid cache exists, Ansible would use.
gathering = smart
[koh@kohs-MBP] ~/vag_test
% time ansible-playbook test.yml

PLAY [Vag1] *****************************************************************************************

TASK [Gathering Facts] ******************************************************************************
ok: [Vag1]

TASK [debug] ****************************************************************************************
ok: [Vag1] => {
    "ansible_hostname": "Vag1"
}

PLAY RECAP ******************************************************************************************
Vag1                       : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

ansible-playbook test.yml  1.02s user 0.30s system 77% cpu 1.713 total
[koh@kohs-MBP] ~/vag_test
% time ansible-playbook test.yml

PLAY [Vag1] *****************************************************************************************

TASK [debug] ****************************************************************************************
ok: [Vag1] => {
    "ansible_hostname": "Vag1"
}

PLAY RECAP ******************************************************************************************
Vag1                       : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

ansible-playbook test.yml  0.69s user 0.20s system 97% cpu 0.901 total
[koh@kohs-MBP] ~/vag_test
%
```

The first run after enabling was pretty much the same as the default since it retrieved the facts, but the second run took only 0.9 second which was 0.8-second faster.

## How Redis works

Let's check what kind of values are in Redis DB.

```
[koh@kohs-MBP] ~/vag_test
% docker exec -it ansibleredis redis-cli
127.0.0.1:6379> keys *
1) "ansible_facts_Vag1"
2) "ansible_cache_keys"
127.0.0.1:6379>
```

There are 2 keys. ansible\_cache\_keys and { fact\_cache\_prefix } { hostname }
```

[koh@kohs-MBP] ~/vag_test
% docker exec -it ansibleredis redis-cli
127.0.0.1:6379> ZRANGE ansible_cache_keys 0 -1
1) "Vag1"
127.0.0.1:6379>
```
ansible\_cache\_keys has a list of cached hosts.  
I have only one target so the number of value should be one too.  

```
[koh@kohs-MBP] ~/vag_test
% docker exec -it ansibleredis redis-cli
127.0.0.1:6379> get ansible_facts_Vag1
"{\n    \"_ansible_facts_gathered\": true,\n    \"ansible_all_ipv4_addresses\": [\n        \"10.0.2.15\",\n        \"192.168.33.11\"\n    ],\n    \"ansible_all_ipv6_addresses\": [\n        \"fe80::590e:8e97:c90c:cc33\",\n        \"fe80::a00:27ff:fe71:612b\"\n    ],\n    \"ansible_apparmor\": {\n        \"status\": \"disabled\"\n    },\n    \"ansible_architecture\": \"x86_64\",\n    \"ansible_bios_date\": \"12/01/2006\",\n    \"ansible_bios_version\": \"VirtualBox\",\n    \"ansible_cmdline\": {\n        \"BOOT_IMAGE\": \"/vmlinuz-3.10.0-862.11.6.el7.x86_64\",\n        \"LANG\": \"en_US.UTF-8\",\n        \"biosdevname\": \"0\",\n        \"crashkernel\": \"auto\",\n        \"net.ifnames\": \"0\",\n        \"quiet\": true,\n        \"rd.lvm.lv\": \"centos/swap\",\n        \"rhgb\": true,\n        \"ro\": true,\n        \"root\": \"/dev/mapper/centos-root\"\n    },\n    \"ansible_date_time\": {\n        \"date\": \"2019-07-17\",\n        \"day\": \"17\",\n        \"epoch\": \"1563371875\",\n        \"hour\": \"22\",\n        \"iso8601\": \"2019-07-17T13:57:55Z\",\n        \"iso8601_basic\": \"20190717T225755697435\",\n        \"iso8601_basic_short\": \"20190717T225755\",\n        \"iso8601_micro\": \"2019-07-17T13:57:55.697505Z\",\n        \"minute\": \"57\",\n        \"month\": \"07\",\n        \"second\": \"55\",\n        \"time\": \"22:57:55\",\n        \"tz\": \"JST\",\n        \"tz_offset\": \"+0900\",\n        \"weekday\": \"Wednesday\",\n        \"weekday_number\": \"3\",\n        \"weeknumber\": \"28\",\n        \"year\": \"2019\"\n    },\n    \"ansible_default_ipv4\": {\n        \"address\": \"10.0.2.15\",\n        \"alias\": \"eth0\",\n        \"broadcast\": \"10.0.2.255\",\n        \"gateway\": \"10.0.2.2\",\n        \"interface\": \"eth0\",\n        \"macaddress\": \"08:00:27:8b:c9:3f\",\n        \"mtu\": 1500,\n        \"netmask\": \"255.255.255.0\",\n        \"network\": \"10.0.2.0\",\n        \"type\": \"ether\"\n    },\n    \"ansible_default_ipv6\": {},\n    \"ansible_device_links\": {\n        \"ids\": {\n            \"dm-0\": [\n                \"dm-name-centos-root\",\n                \"dm-uuid-LVM-cXud4zK75fureDdfCQfo5enloeKDIc3rbL1yYbzzPZGdVlveHAelfn7TdiL4PPMK\"\n            ],\n            \"dm-1\": [\n                \"dm-name-centos-swap\",\n                \"dm-uuid-LVM-cXud4zK75fureDdfCQfo5enloeKDIc3r5Se12VYk5F7OofGC3mzqUxBtHLOc6f0i\"\n            ],\n            \"dm-2\": [\n                \"dm-name-centos-home\",\n                \"dm-uuid-LVM-cXud4zK75fureDdfCQfo5enloeKDIc3rBnDGTj2yA0ImV13Ife64zvRL20DXAcBp\"\n            ],\n            \"sda\": [\n                \"ata-VBOX_HARDDISK_VB1c9995b6-54c424af\"\n            ],\n            \"sda1\": [\n                \"ata-VBOX_HARDDISK_VB1c9995b6-54c424af-part1\"\n            ],\n            \"sda2\": [\n                \"ata-VBOX_HARDDISK_VB1c9995b6-54c424af-part2\",\n                \"lvm-pv-uuid-xkveE6-q5bs-AFQm-GG2X-lWDs-nZNn-v1DuLs\"\n            ]\n        },\n        \"labels\": {},\n        \"masters\": {\n            \"sda2\": [\n                \"dm-0\",\n                \"dm-1\",\n                \"dm-2\"\n            ]\n        },\n        \"uuids\": {\n            \"dm-0\": [\n                \"214cf212-d7f8-41fe-89a4-6b5e1f1d469c\"\n            ],\n            \"dm-1\": [\n                \"0f5a6474-6d09-4220-8eb4-f97e79b41ea0\"\n            ],\n            \"dm-2\": [\n                \"0fb2cf77-ad36-4728-a3f5-b53dc134e3fd\"\n            ],\n            \"sda1\": [\n                \"ec9d8bfa-8da0-43ce-b469-f0178aa904b5\"\n            ]\n        }\n    },\n    \"ansible_devices\": {\n        \"dm-0\": {\n            \"holders\": [],\n            \"host\": \"\",\n            \"links\": {\n                \"ids\": [\n                    \"dm-name-centos-root\",\n                    \"dm-uuid-LVM-cXud4zK75fureDdfCQfo5enloeKDIc3rbL1yYbzzPZGdVlveHAelfn7TdiL4PPMK\"\n                ],\n                \"labels\": [],\n                \"masters\": [],\n                \"uuids\": [\n                    \"214cf212-d7f8-41fe-89a4-6b5e1f1d469c\"\n                ]\n            },\n            \"model\": null,\n            \"partitions\": {},\n            \"removable\": \"0\",\n            \"rotational\": \"1\",\n            \"sas_address\": null,\n            \"sas_device_handle\": null,\n            \"scheduler_mode\": \"\",\n            \"sectors\": \"85950464\",\n            \"sectorsize\": \"512\",\n            \"size\": \"40.98 GB\",\n            \"support_discard\": \"0\",\n            \"vendor\": null,\n            \"virtual\": 1\n        },\n        \"dm-1\": {\n            \"holders\": [],\n            \"host\": \"\",\n            \"links\": {\n                \"ids\": [\n                    \"dm-name-centos-swap\",\n                    \"dm-uuid-LVM-cXud4zK75fureDdfCQfo5enloeKDIc3r5Se12VYk5F7OofGC3mzqUxBtHLOc6f0i\"\n                ],\n                \"labels\": [],\n                \"masters\": [],\n                \"uuids\": [\n                    \"0f5a6474-6d09-4220-8eb4-f97e79b41ea0\"\n                ]\n            },\n            \"model\": null,\n            \"partitions\": {},\n            \"removable\": \"0\",\n            \"rotational\": \"1\",\n            \"sas_address\": null,\n            \"sas_device_handle\": null,\n            \"scheduler_mode\": \"\",\n            \"sectors\": \"4194304\",\n            \"sectorsize\": \"512\",\n            \"size\": \"2.00 GB\",\n            \"support_discard\": \"0\",\n            \"vendor\": null,\n            \"virtual\": 1\n        },\n        \"dm-2\": {\n            \"holders\": [],\n            \"host\": \"\",\n            \"links\": {\n                \"ids\": [\n                    \"dm-name-centos-home\",\n                    \"dm-uuid-LVM-cXud4zK75fureDdfCQfo5enloeKDIc3rBnDGTj2yA0ImV13Ife64zvRL20DXAcBp\"\n                ],\n                \"labels\": [],\n                \"masters\": [],\n                \"uuids\": [\n                    \"0fb2cf77-ad36-4728-a3f5-b53dc134e3fd\"\n                ]\n            },\n            \"model\": null,\n            \"partitions\": {},\n            \"removable\": \"0\",\n            \"rotational\": \"1\",\n            \"sas_address\": null,\n            \"sas_device_handle\": null,\n            \"scheduler_mode\": \"\",\n            \"sectors\": \"41959424\",\n            \"sectorsize\": \"512\",\n            \"size\": \"20.01 GB\",\n            \"support_discard\": \"0\",\n            \"vendor\": null,\n            \"virtual\": 1\n        },\n        \"sda\": {\n            \"holders\": [],\n            \"host\": \"\",\n            \"links\": {\n                \"ids\": [\n                    \"ata-VBOX_HARDDISK_VB1c9995b6-54c424af\"\n                ],\n                \"labels\": [],\n                \"masters\": [],\n                \"uuids\": []\n            },\n            \"model\": \"VBOX HARDDISK\",\n            \"partitions\": {\n                \"sda1\": {\n                    \"holders\": [],\n                    \"links\": {\n                        \"ids\": [\n                            \"ata-VBOX_HARDDISK_VB1c9995b6-54c424af-part1\"\n                        ],\n                        \"labels\": [],\n                        \"masters\": [],\n                        \"uuids\": [\n                            \"ec9d8bfa-8da0-43ce-b469-f0178aa904b5\"\n                        ]\n                    },\n                    \"sectors\": \"2097152\",\n                    \"sectorsize\": 512,\n                    \"size\": \"1.00 GB\",\n                    \"start\": \"2048\",\n                    \"uuid\": \"ec9d8bfa-8da0-43ce-b469-f0178aa904b5\"\n                },\n                \"sda2\": {\n                    \"holders\": [\n                        \"centos-root\",\n                        \"centos-swap\",\n                        \"centos-home\"\n                    ],\n                    \"links\": {\n                        \"ids\": [\n                            \"ata-VBOX_HARDDISK_VB1c9995b6-54c424af-part2\",\n                            \"lvm-pv-uuid-xkveE6-q5bs-AFQm-GG2X-lWDs-nZNn-v1DuLs\"\n                        ],\n                        \"labels\": [],\n                        \"masters\": [\n                            \"dm-0\",\n                            \"dm-1\",\n                            \"dm-2\"\n                        ],\n                        \"uuids\": []\n                    },\n                    \"sectors\": \"132118528\",\n                    \"sectorsize\": 512,\n                    \"size\": \"63.00 GB\",\n                    \"start\": \"2099200\",\n                    \"uuid\": null\n                }\n            },\n            \"removable\": \"0\",\n            \"rotational\": \"1\",\n            \"sas_address\": null,\n            \"sas_device_handle\": null,\n            \"scheduler_mode\": \"deadline\",\n            \"sectors\": \"134217728\",\n            \"sectorsize\": \"512\",\n            \"size\": \"64.00 GB\",\n            \"support_discard\": \"0\",\n            \"vendor\": \"ATA\",\n            \"virtual\": 1\n        }\n    },\n    \"ansible_distribution\": \"CentOS\",\n    \"ansible_distribution_file_parsed\": true,\n    \"ansible_distribution_file_path\": \"/etc/redhat-release\",\n    \"ansible_distribution_file_variety\": \"RedHat\",\n    \"ansible_distribution_major_version\": \"7\",\n    \"ansible_distribution_release\": \"Core\",\n    \"ansible_distribution_version\": \"7\",\n    \"ansible_dns\": {},\n    \"ansible_domain\": \"\",\n    \"ansible_effective_group_id\": 1000,\n    \"ansible_effective_user_id\": 1000,\n    \"ansible_env\": {\n        \"HOME\": \"/home/vagrant\",\n        \"LANG\": \"C\",\n        \"LC_ALL\": \"C\",\n        \"LC_CTYPE\": \"UTF-8\",\n        \"LC_MESSAGES\": \"C\",\n        \"LOGNAME\": \"vagrant\",\n        \"MAIL\": \"/var/mail/vagrant\",\n        \"PATH\": \"/usr/local/bin:/usr/bin\",\n        \"PWD\": \"/home/vagrant\",\n        \"SELINUX_LEVEL_REQUESTED\": \"\",\n        \"SELINUX_ROLE_REQUESTED\": \"\",\n        \"SELINUX_USE_CURRENT_RANGE\": \"\",\n        \"SHELL\": \"/usr/bin/zsh\",\n        \"SHLVL\": \"1\",\n        \"SSH_CLIENT\": \"192.168.33.1 57299 22\",\n        \"SSH_CONNECTION\": \"192.168.33.1 57299 192.168.33.11 22\",\n        \"SSH_TTY\": \"/dev/pts/0\",\n        \"TERM\": \"xterm-256color\",\n        \"USER\": \"vagrant\",\n        \"XDG_RUNTIME_DIR\": \"/run/user/1000\",\n        \"XDG_SESSION_ID\": \"17\",\n        \"_\": \"/usr/bin/python\"\n    },\n    \"ansible_eth0\": {\n        \"active\": true,\n        \"device\": \"eth0\",\n        \"features\": {\n            \"busy_poll\": \"off [fixed]\",\n            \"fcoe_mtu\": \"off [fixed]\",\n            \"generic_receive_offload\": \"on\",\n            \"generic_segmentation_offload\": \"on\",\n            \"highdma\": \"off [fixed]\",\n            \"hw_tc_offload\": \"off [fixed]\",\n            \"l2_fwd_offload\": \"off [fixed]\",\n            \"large_receive_offload\": \"off [fixed]\",\n            \"loopback\": \"off [fixed]\",\n            \"netns_local\": \"off [fixed]\",\n            \"ntuple_filters\": \"off [fixed]\",\n            \"receive_hashing\": \"off [fixed]\",\n            \"rx_all\": \"off\",\n            \"rx_checksumming\": \"off\",\n            \"rx_fcs\": \"off\",\n            \"rx_udp_tunnel_port_offload\": \"off [fixed]\",\n            \"rx_vlan_filter\": \"on [fixed]\",\n            \"rx_vlan_offload\": \"on\",\n            \"rx_vlan_stag_filter\": \"off [fixed]\",\n            \"rx_vlan_stag_hw_parse\": \"off [fixed]\",\n            \"scatter_gather\": \"on\",\n            \"tcp_segmentation_offload\": \"on\",\n            \"tx_checksum_fcoe_crc\": \"off [fixed]\",\n            \"tx_checksum_ip_generic\": \"on\",\n            \"tx_checksum_ipv4\": \"off [fixed]\",\n            \"tx_checksum_ipv6\": \"off [fixed]\",\n            \"tx_checksum_sctp\": \"off [fixed]\",\n            \"tx_checksumming\": \"on\",\n            \"tx_fcoe_segmentation\": \"off [fixed]\",\n            \"tx_gre_csum_segmentation\": \"off [fixed]\",\n            \"tx_gre_segmentation\": \"off [fixed]\",\n            \"tx_gso_partial\": \"off [fixed]\",\n            \"tx_gso_robust\": \"off [fixed]\",\n            \"tx_ipip_segmentation\": \"off [fixed]\",\n            \"tx_lockless\": \"off [fixed]\",\n            \"tx_nocache_copy\": \"off\",\n            \"tx_scatter_gather\": \"on\",\n            \"tx_scatter_gather_fraglist\": \"off [fixed]\",\n            \"tx_sctp_segmentation\": \"off [fixed]\",\n            \"tx_sit_segmentation\": \"off [fixed]\",\n            \"tx_tcp6_segmentation\": \"off [fixed]\",\n            \"tx_tcp_ecn_segmentation\": \"off [fixed]\",\n            \"tx_tcp_mangleid_segmentation\": \"off\",\n            \"tx_tcp_segmentation\": \"on\",\n            \"tx_udp_tnl_csum_segmentation\": \"off [fixed]\",\n            \"tx_udp_tnl_segmentation\": \"off [fixed]\",\n            \"tx_vlan_offload\": \"on [fixed]\",\n            \"tx_vlan_stag_hw_insert\": \"off [fixed]\",\n            \"udp_fragmentation_offload\": \"off [fixed]\",\n            \"vlan_challenged\": \"off [fixed]\"\n        },\n        \"hw_timestamp_filters\": [],\n        \"ipv4\": {\n            \"address\": \"10.0.2.15\",\n            \"broadcast\": \"10.0.2.255\",\n            \"netmask\": \"255.255.255.0\",\n            \"network\": \"10.0.2.0\"\n        },\n        \"ipv6\": [\n            {\n                \"address\": \"fe80::590e:8e97:c90c:cc33\",\n                \"prefix\": \"64\",\n                \"scope\": \"link\"\n            }\n        ],\n        \"macaddress\": \"08:00:27:8b:c9:3f\",\n        \"module\": \"e1000\",\n        \"mtu\": 1500,\n        \"pciid\": \"0000:00:03.0\",\n        \"promisc\": false,\n        \"speed\": 1000,\n        \"timestamping\": [\n            \"tx_software\",\n            \"rx_software\",\n            \"software\"\n        ],\n        \"type\": \"ether\"\n    },\n    \"ansible_eth1\": {\n        \"active\": true,\n        \"device\": \"eth1\",\n        \"features\": {\n            \"busy_poll\": \"off [fixed]\",\n            \"fcoe_mtu\": \"off [fixed]\",\n            \"generic_receive_offload\": \"on\",\n            \"generic_segmentation_offload\": \"on\",\n            \"highdma\": \"off [fixed]\",\n            \"hw_tc_offload\": \"off [fixed]\",\n            \"l2_fwd_offload\": \"off [fixed]\",\n            \"large_receive_offload\": \"off [fixed]\",\n            \"loopback\": \"off [fixed]\",\n            \"netns_local\": \"off [fixed]\",\n            \"ntuple_filters\": \"off [fixed]\",\n            \"receive_hashing\": \"off [fixed]\",\n            \"rx_all\": \"off\",\n            \"rx_checksumming\": \"off\",\n            \"rx_fcs\": \"off\",\n            \"rx_udp_tunnel_port_offload\": \"off [fixed]\",\n            \"rx_vlan_filter\": \"on [fixed]\",\n            \"rx_vlan_offload\": \"on\",\n            \"rx_vlan_stag_filter\": \"off [fixed]\",\n            \"rx_vlan_stag_hw_parse\": \"off [fixed]\",\n            \"scatter_gather\": \"on\",\n            \"tcp_segmentation_offload\": \"on\",\n            \"tx_checksum_fcoe_crc\": \"off [fixed]\",\n            \"tx_checksum_ip_generic\": \"on\",\n            \"tx_checksum_ipv4\": \"off [fixed]\",\n            \"tx_checksum_ipv6\": \"off [fixed]\",\n            \"tx_checksum_sctp\": \"off [fixed]\",\n            \"tx_checksumming\": \"on\",\n            \"tx_fcoe_segmentation\": \"off [fixed]\",\n            \"tx_gre_csum_segmentation\": \"off [fixed]\",\n            \"tx_gre_segmentation\": \"off [fixed]\",\n            \"tx_gso_partial\": \"off [fixed]\",\n            \"tx_gso_robust\": \"off [fixed]\",\n            \"tx_ipip_segmentation\": \"off [fixed]\",\n            \"tx_lockless\": \"off [fixed]\",\n            \"tx_nocache_copy\": \"off\",\n            \"tx_scatter_gather\": \"on\",\n            \"tx_scatter_gather_fraglist\": \"off [fixed]\",\n            \"tx_sctp_segmentation\": \"off [fixed]\",\n            \"tx_sit_segmentation\": \"off [fixed]\",\n            \"tx_tcp6_segmentation\": \"off [fixed]\",\n            \"tx_tcp_ecn_segmentation\": \"off [fixed]\",\n            \"tx_tcp_mangleid_segmentation\": \"off\",\n            \"tx_tcp_segmentation\": \"on\",\n            \"tx_udp_tnl_csum_segmentation\": \"off [fixed]\",\n            \"tx_udp_tnl_segmentation\": \"off [fixed]\",\n            \"tx_vlan_offload\": \"on [fixed]\",\n            \"tx_vlan_stag_hw_insert\": \"off [fixed]\",\n            \"udp_fragmentation_offload\": \"off [fixed]\",\n            \"vlan_challenged\": \"off [fixed]\"\n        },\n        \"hw_timestamp_filters\": [],\n        \"ipv4\": {\n            \"address\": \"192.168.33.11\",\n            \"broadcast\": \"192.168.33.255\",\n            \"netmask\": \"255.255.255.0\",\n            \"network\": \"192.168.33.0\"\n        },\n        \"ipv6\": [\n            {\n                \"address\": \"fe80::a00:27ff:fe71:612b\",\n                \"prefix\": \"64\",\n                \"scope\": \"link\"\n            }\n        ],\n        \"macaddress\": \"08:00:27:71:61:2b\",\n        \"module\": \"e1000\",\n        \"mtu\": 1500,\n        \"pciid\": \"0000:00:08.0\",\n        \"promisc\": false,\n        \"speed\": 1000,\n        \"timestamping\": [\n            \"tx_software\",\n            \"rx_software\",\n            \"software\"\n        ],\n        \"type\": \"ether\"\n    },\n    \"ansible_fibre_channel_wwn\": [],\n    \"ansible_fips\": false,\n    \"ansible_form_factor\": \"Other\",\n    \"ansible_fqdn\": \"Vag1\",\n    \"ansible_hostname\": \"Vag1\",\n    \"ansible_hostnqn\": \"\",\n    \"ansible_interfaces\": [\n        \"lo\",\n        \"eth1\",\n        \"eth0\"\n    ],\n    \"ansible_is_chroot\": true,\n    \"ansible_iscsi_iqn\": \"\",\n    \"ansible_kernel\": \"3.10.0-862.11.6.el7.x86_64\",\n    \"ansible_lo\": {\n        \"active\": true,\n        \"device\": \"lo\",\n        \"features\": {\n            \"busy_poll\": \"off [fixed]\",\n            \"fcoe_mtu\": \"off [fixed]\",\n            \"generic_receive_offload\": \"on\",\n            \"generic_segmentation_offload\": \"on\",\n            \"highdma\": \"on [fixed]\",\n            \"hw_tc_offload\": \"off [fixed]\",\n            \"l2_fwd_offload\": \"off [fixed]\",\n            \"large_receive_offload\": \"off [fixed]\",\n            \"loopback\": \"on [fixed]\",\n            \"netns_local\": \"on [fixed]\",\n            \"ntuple_filters\": \"off [fixed]\",\n            \"receive_hashing\": \"off [fixed]\",\n            \"rx_all\": \"off [fixed]\",\n            \"rx_checksumming\": \"on [fixed]\",\n            \"rx_fcs\": \"off [fixed]\",\n            \"rx_udp_tunnel_port_offload\": \"off [fixed]\",\n            \"rx_vlan_filter\": \"off [fixed]\",\n            \"rx_vlan_offload\": \"off [fixed]\",\n            \"rx_vlan_stag_filter\": \"off [fixed]\",\n            \"rx_vlan_stag_hw_parse\": \"off [fixed]\",\n            \"scatter_gather\": \"on\",\n            \"tcp_segmentation_offload\": \"on\",\n            \"tx_checksum_fcoe_crc\": \"off [fixed]\",\n            \"tx_checksum_ip_generic\": \"on [fixed]\",\n            \"tx_checksum_ipv4\": \"off [fixed]\",\n            \"tx_checksum_ipv6\": \"off [fixed]\",\n            \"tx_checksum_sctp\": \"on [fixed]\",\n            \"tx_checksumming\": \"on\",\n            \"tx_fcoe_segmentation\": \"off [fixed]\",\n            \"tx_gre_csum_segmentation\": \"off [fixed]\",\n            \"tx_gre_segmentation\": \"off [fixed]\",\n            \"tx_gso_partial\": \"off [fixed]\",\n            \"tx_gso_robust\": \"off [fixed]\",\n            \"tx_ipip_segmentation\": \"off [fixed]\",\n            \"tx_lockless\": \"on [fixed]\",\n            \"tx_nocache_copy\": \"off [fixed]\",\n            \"tx_scatter_gather\": \"on [fixed]\",\n            \"tx_scatter_gather_fraglist\": \"on [fixed]\",\n            \"tx_sctp_segmentation\": \"on\",\n            \"tx_sit_segmentation\": \"off [fixed]\",\n            \"tx_tcp6_segmentation\": \"on\",\n            \"tx_tcp_ecn_segmentation\": \"on\",\n            \"tx_tcp_mangleid_segmentation\": \"on\",\n            \"tx_tcp_segmentation\": \"on\",\n            \"tx_udp_tnl_csum_segmentation\": \"off [fixed]\",\n            \"tx_udp_tnl_segmentation\": \"off [fixed]\",\n            \"tx_vlan_offload\": \"off [fixed]\",\n            \"tx_vlan_stag_hw_insert\": \"off [fixed]\",\n            \"udp_fragmentation_offload\": \"on\",\n            \"vlan_challenged\": \"on [fixed]\"\n        },\n        \"hw_timestamp_filters\": [],\n        \"ipv4\": {\n            \"address\": \"127.0.0.1\",\n            \"broadcast\": \"host\",\n            \"netmask\": \"255.0.0.0\",\n            \"network\": \"127.0.0.0\"\n        },\n        \"ipv6\": [\n            {\n                \"address\": \"::1\",\n                \"prefix\": \"128\",\n                \"scope\": \"host\"\n            }\n        ],\n        \"mtu\": 65536,\n        \"promisc\": false,\n        \"timestamping\": [\n            \"rx_software\",\n            \"software\"\n        ],\n        \"type\": \"loopback\"\n    },\n    \"ansible_local\": {},\n    \"ansible_lsb\": {},\n    \"ansible_machine\": \"x86_64\",\n    \"ansible_machine_id\": \"b8ae4e7c6e42490b801633d8d903c9a0\",\n    \"ansible_memfree_mb\": 769,\n    \"ansible_memory_mb\": {\n        \"nocache\": {\n            \"free\": 874,\n            \"used\": 117\n        },\n        \"real\": {\n            \"free\": 769,\n            \"total\": 991,\n            \"used\": 222\n        },\n        \"swap\": {\n            \"cached\": 0,\n            \"free\": 2047,\n            \"total\": 2047,\n            \"used\": 0\n        }\n    },\n    \"ansible_memtotal_mb\": 991,\n    \"ansible_mounts\": [\n        {\n            \"block_available\": 226495,\n            \"block_size\": 4096,\n            \"block_total\": 259584,\n            \"block_used\": 33089,\n            \"device\": \"/dev/sda1\",\n            \"fstype\": \"xfs\",\n            \"inode_available\": 523962,\n            \"inode_total\": 524288,\n            \"inode_used\": 326,\n            \"mount\": \"/boot\",\n            \"options\": \"rw,seclabel,relatime,attr2,inode64,noquota\",\n            \"size_available\": 927723520,\n            \"size_total\": 1063256064,\n            \"uuid\": \"ec9d8bfa-8da0-43ce-b469-f0178aa904b5\"\n        },\n        {\n            \"block_available\": 10398487,\n            \"block_size\": 4096,\n            \"block_total\": 10738562,\n            \"block_used\": 340075,\n            \"device\": \"/dev/mapper/centos-root\",\n            \"fstype\": \"xfs\",\n            \"inode_available\": 21453369,\n            \"inode_total\": 21487616,\n            \"inode_used\": 34247,\n            \"mount\": \"/\",\n            \"options\": \"rw,seclabel,relatime,attr2,inode64,noquota\",\n            \"size_available\": 42592202752,\n            \"size_total\": 43985149952,\n            \"uuid\": \"214cf212-d7f8-41fe-89a4-6b5e1f1d469c\"\n        },\n        {\n            \"block_available\": 5233400,\n            \"block_size\": 4096,\n            \"block_total\": 5242367,\n            \"block_used\": 8967,\n            \"device\": \"/dev/mapper/centos-home\",\n            \"fstype\": \"xfs\",\n            \"inode_available\": 10489816,\n            \"inode_total\": 10489856,\n            \"inode_used\": 40,\n            \"mount\": \"/home\",\n            \"options\": \"rw,seclabel,relatime,attr2,inode64,noquota\",\n            \"size_available\": 21436006400,\n            \"size_total\": 21472735232,\n            \"uuid\": \"0fb2cf77-ad36-4728-a3f5-b53dc134e3fd\"\n        }\n    ],\n    \"ansible_nodename\": \"Vag1\",\n    \"ansible_os_family\": \"RedHat\",\n    \"ansible_pkg_mgr\": \"yum\",\n    \"ansible_proc_cmdline\": {\n        \"BOOT_IMAGE\": \"/vmlinuz-3.10.0-862.11.6.el7.x86_64\",\n        \"LANG\": \"en_US.UTF-8\",\n        \"biosdevname\": \"0\",\n        \"crashkernel\": \"auto\",\n        \"net.ifnames\": \"0\",\n        \"quiet\": true,\n        \"rd.lvm.lv\": [\n            \"centos/root\",\n            \"centos/swap\"\n        ],\n        \"rhgb\": true,\n        \"ro\": true,\n        \"root\": \"/dev/mapper/centos-root\"\n    },\n    \"ansible_processor\": [\n        \"0\",\n        \"GenuineIntel\",\n        \"Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\"\n    ],\n    \"ansible_processor_cores\": 1,\n    \"ansible_processor_count\": 1,\n    \"ansible_processor_threads_per_core\": 1,\n    \"ansible_processor_vcpus\": 1,\n    \"ansible_product_name\": \"VirtualBox\",\n    \"ansible_product_serial\": \"NA\",\n    \"ansible_product_uuid\": \"NA\",\n    \"ansible_product_version\": \"1.2\",\n    \"ansible_python\": {\n        \"executable\": \"/usr/bin/python\",\n        \"has_sslcontext\": true,\n        \"type\": \"CPython\",\n        \"version\": {\n            \"major\": 2,\n            \"micro\": 5,\n            \"minor\": 7,\n            \"releaselevel\": \"final\",\n            \"serial\": 0\n        },\n        \"version_info\": [\n            2,\n            7,\n            5,\n            \"final\",\n            0\n        ]\n    },\n    \"ansible_python_version\": \"2.7.5\",\n    \"ansible_real_group_id\": 1000,\n    \"ansible_real_user_id\": 1000,\n    \"ansible_selinux\": {\n        \"config_mode\": \"enforcing\",\n        \"mode\": \"enforcing\",\n        \"policyvers\": 31,\n        \"status\": \"enabled\",\n        \"type\": \"targeted\"\n    },\n    \"ansible_selinux_python_present\": true,\n    \"ansible_service_mgr\": \"systemd\",\n    \"ansible_ssh_host_key_ecdsa_public\": \"AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBA5XlGiLVt6/NnCPwaH89VKPo+cvKjyzwnje1z9LkaiFXRNhWTsxYsMYPjx5cf5HQbJs4VCKIaPxK20QFYSabLc=\",\n    \"ansible_ssh_host_key_ed25519_public\": \"AAAAC3NzaC1lZDI1NTE5AAAAIGhrt2KMmJ0a2QdNNsFElTnHSdhufURJmAIo39+5R1hP\",\n    \"ansible_ssh_host_key_rsa_public\": \"AAAAB3NzaC1yc2EAAAADAQABAAABAQC99JJpb04/QLprQKr1Duz7dBfAHvbwuaouvVkMPKVoxQ7u2xUiTqKMWwckPBw3GfRC+soM6KXj+WnaIFsIFmYBYOwN1dl4ldpJxvp/+rz4VUvOsjqiAK6Ju7Hi2zlvN/Cz8n8NMC7+BT295s1jGYJU7SGVVJ/uLDVoiDa/dcptk17V4bgN8Wqe3hiEDbtbRMgZdwQ01o8b1uM6GQAAbz1S6kwnZ3fOXHU7Z29lZu2g5/xIYX48yhV8YnqwWmI2+i0zd06b+HoXwQH2+OVlZEMfv2Gc+xp4E0Pqu6VDyOPJGIkRuV0aBX6qT/6FDBUWvcGXs7gVdUL2wdvi5V8uf/rV\",\n    \"ansible_swapfree_mb\": 2047,\n    \"ansible_swaptotal_mb\": 2047,\n    \"ansible_system\": \"Linux\",\n    \"ansible_system_capabilities\": [\n        \"\"\n    ],\n    \"ansible_system_capabilities_enforced\": \"True\",\n    \"ansible_system_vendor\": \"innotek GmbH\",\n    \"ansible_uptime_seconds\": 3839,\n    \"ansible_user_dir\": \"/home/vagrant\",\n    \"ansible_user_gecos\": \"vagrant\",\n    \"ansible_user_gid\": 1000,\n    \"ansible_user_id\": \"vagrant\",\n    \"ansible_user_shell\": \"/usr/bin/zsh\",\n    \"ansible_user_uid\": 1000,\n    \"ansible_userspace_architecture\": \"x86_64\",\n    \"ansible_userspace_bits\": \"64\",\n    \"ansible_virtualization_role\": \"guest\",\n    \"ansible_virtualization_type\": \"virtualbox\",\n    \"discovered_interpreter_python\": \"/usr/bin/python\",\n    \"gather_subset\": [\n        \"all\"\n    ],\n    \"module_setup\": true\n}"
127.0.0.1:6379>
```

As you see that is how facts are registered to Redis.

Right after running Playbook, I checked TTL of the key and the value was the same as  fact_caching_timeout.

```
[koh@kohs-MBP] ~/vag_test
% docker exec -it ansibleredis redis-cli
127.0.0.1:6379> ttl ansible_facts_Vag1
(integer) 57
127.0.0.1:6379>
```

## Conclusion

Now we know how to make Ansible only a bit faster.
It is only a few seconds but might be useful when you have to run Playbook many times.
Also please be noted that if Redis is down, Ansible cannot be run.
So if you are interested in using this for production CI/CD, you have to ensure the availability of Redis.