Ansible Detailed Explanation (16) - Ansible with Redis

Today, I will continue to introduce the relevant knowledge of Linux operation and maintenance. The main content of this article is that Ansible cooperates with Redis to cache client information collection to speed up the execution of Ansible.

1. Redis service deployment

First, let's deploy the Redis service, first download the Redis service, and decompress it. After decompression, go to the directory after the section and execute the command:

make prefix=/usr/local/redis install
cp redis.conf /usr/local/redis/redis/conf

In this way, the Redis service is installed. Next, we configure the startup environment of Redis and execute the command:

export PATH=/usr/local/redis/bin:$PATH
source /etc/profile

Next, we install the Python module of Redis and execute the command:

yum install -y python-pip
pip install redis==3.4.1

Note: At present, many other online tutorials let the command pip install redis be executed. This is the previous practice. At present, due to the update of the Python version, this command is no longer available. We must manually specify the version installed by pip. Therefore, we must execute the above. that order. After the above command is executed, the result is as follows:
insert image description here

2. Ansible integrates Redis

After completing the above configuration, we also need to configure Ansible to support Redis. Open the /etc/ansible/ansible.cfg file and add the following to the defaults module:

gathering = smart
fact_caching = redis
fact_caching_timeout = 86400
fact_caching_connection = localhost:6379

After joining, the configuration file looks like this:
insert image description here

3. Effect test

Finally, let's check the results of the configuration just now.
First, open the Redis database and execute the command:

nohup /usr/local/redis/bin/redis-server  /usr/local/redis/redis.conf  &

You can see that port 6379 is enabled on the Ansible device, as shown below:
insert image description here
Then we use ansible-playbook to randomly execute a Playbook, and then enter the Redis database to view the contents of the Redis database. The results are as follows: As
insert image description here
you can see, Ansible The fact host information is stored in the Redis cache, and Ansible is successfully configured with the Redis cache!
Originality is not easy, please indicate the source for reprinting: https://blog.csdn.net/weixin_40228200

Guess you like

Origin blog.csdn.net/weixin_40228200/article/details/123579927