In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
What is idempotency in ansible? How do I use it? In fact, all these troubles can be summed up as a problem, that is, the use of idempotency in ansible? It's not difficult to solve this problem, so let's take a look at the use of idempotency in ansible.
1. Idempotency in ansible
The vast majority of modules in ansible are idempotent, meaning that execution in turn or multiple times has no side effects. However, shell, command, script and raw are not idempotent, and all operations are repeated, but some operations are not allowed to be repeated, such as MySQL's initialization command mysql_install_db, which is logically initialized in sequence during the first configuration and should not be executed at any other time. Therefore, whenever you use these four modules, think about whether repeated execution of this command will have a negative impact.
Of course, of the above four modules, except for the raw module, all provide parameters that implement idempotent properties, namely creates and removes:
Creates parameter: the command is not executed when the specified file or directory exists; removes parameter: when the specified file or directory does not exist, the command is not executed
Examples are as follows:
-name: use some module hosts: node gather_facts: false tasks: # do not execute if the network card configuration file does not exist-name: use command module command: ifup ens33 args: removes: / etc/sysconfig/network-scripts/ifcfg-ens33 # mysql configuration file does not exist, avoid overwriting-name: use shell module shell: cp / tmp/my.cnf / etc/my.cnf args: creates: / etc/my.cnf
After testing, it can be proved that after using the removes or creates parameters, you can achieve idempotency and ensure that the command will not be repeated.
None of these four modules is limited to executing shell commands or shell scripts. You can specify other interpreters through the executable parameter, such as expec executes expect scripts, perl interpreters execute perl scripts, and so on. As follows:
[root@ansible ansible] # cat test.yaml-name: RUN a perl script script: / some/local/script.pl args: executable: perl
The above is the use of idempotency in ansible introduction, detailed use of their own use to know the specific essentials. If you want to read more related articles, you are welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.