当前位置:网站首页>Ansible ad-hoc temporary command
Ansible ad-hoc temporary command
2022-06-30 01:21:00 【Foxconn quality inspector zhangquandan】
ad-hoc What is it?
ad-hoc In short " Provisional order ", The execution is over , Not saved , That is, the execution of a module is over , If you want her to run over and over again , No way. . Unlike writing multiple commands to a file , It can be run over and over again .
- Application scenarios 1∶ Check whether the processes of multiple nodes exist
- Application scenarios 2∶ Copy the specified file to the local
[[email protected] ~]# ansible webservers -m shell -a "ps -aux | grep nginx" -i /etc/ansible/hosts[[email protected] ~]# ansible webservers -m shell -a "touch /root/ansible.txt" -i /etc/ansible/hostsad-hoc Command to use
Order sample ∶ansible 'groups' -m command -a 'df -h', The meaning is shown in the figure below ;

shell Modules can actually solve many problems , But this module is definitely not enough , and shell Module cannot guarantee idempotency , Other modules also contain other functions .
ad-hoc Execution process
- Load your own profile , Default /etc/ans1b1e/ansible.cfg
- Find the corresponding host configuration file , Find the host or group to execute
- Load the corresponding module file , Such as command
- adopt ansible Generate the module or command corresponding to the temporary py file , And transfer the file to the remote server for corresponding execution user $HOME/.ansible/tmp/ansible-tmp-nurber/XX.PY( This file is invisible , It is deleted after execution )( The controlled end is called Python To resolve this temporary py file , And then call shell To run , It is deleted after running )
- Execute the... Of the user's home directory ` file
- Give the papers +x perform
- Execute and return results
- Delete temporary py file ,sleep 0 sign out
[[email protected] ~]# ansible webservers -m shell -a "sleep 10" -i /etc/ansible/hosts
[[email protected] tmp]# ls ansible-tmp-1656102874.99-71725-64844177037053/
AnsiballZ_command.py
[[email protected] tmp]# pwd
/root/.ansible/tmpad-hoc Execution status
Use ad-hoc Execute a remote command , Notice the color of the returned result ;
- green ∶ Represents that the managed end host has not been modified
- yellow ∶ On behalf of the managed end host, changes are found
- Red : It means something's wrong , Pay attention to the tips
Demonstrate creating a project and using ad-hoc
[[email protected] ~]# mkdir -p project
[[email protected] ~]# cd project/
[[email protected] project]# cp /etc/ansible/ansible.cfg .
[[email protected] project]# cp /etc/ansible/hosts .
[[email protected] project]# ls
ansible.cfg hostsNow the configuration read by the project is /root/project/ansible.cfg
[[email protected] project]# ansible --version
ansible 2.9.27
config file = /root/project/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)][[email protected] project]# vim ansible.cfg
inventory = /root/project/hosts # The absolute path can be written here , You can also write relative paths /hostsHere you can also adjust forks,1 On behalf of one by one execution ,5 On behalf of concurrent execution 5 platform
forks = 5 # Adjust the number of parallel hosts This parameter can be increased during optimization , Adjust the number of machines to the number of machines , This will make the execution effect faster , Or one by one
[[email protected] project]# ansible webservers -m shell -a "sleep 3" -f 1
192.168.111.6 | CHANGED | rc=0 >>
192.168.111.7 | CHANGED | rc=0 >>
192.168.111.8 | CHANGED | rc=0 >>
[[email protected] project]# ansible webservers -m shell -a "sleep 3" -f 5
192.168.111.8 | CHANGED | rc=0 >>
192.168.111.7 | CHANGED | rc=0 >>
192.168.111.6 | CHANGED | rc=0 >>Ansible Common modules
ansible There are many modules , Although there are many modules , But the most commonly used modules are 20-30 about
Commonly used ad-hoc: modular :
0. test shell | command
0. download get_url
1. install yum | yum_repository
2. To configure copy | template
3. initialization file create a file , Create directory , to grant authorization
4. user | Group user group
4. start-up systemd
6. mount mount
7. Timing task cron
8. A firewall firewalld | iptables
9. File content modification lineinfile
边栏推荐
- Netease cloud music beta music social app "mus" matches friends of the same frequency through music
- How to unify the use of package manager in a project?
- shell 规范日期格式
- 2022-06-29: x = {a, B, C, D}, y = {e, F, G, H}, the length of the two small arrays X and Y is 4. If yes: a + e = B + F = C + G = D + H
- Application of pointer in STC89C52 single chip microcomputer and demonstration of practical cases
- 传统微服务框架如何无缝过渡到服务网格 ASM
- Vl6180x distance and light sensor hands-on experience
- 首届·技术播客月开播在即
- Can mango hypermedia, which "braves the wind and waves", go ashore?
- The 8th "Internet +" competition - cloud native track invites you to challenge
猜你喜欢

Quality management of functional modules of MES management system
![Cantilever beam calculation [matlab code]](/img/f6/9a1338e00777e91f6c340eae9d52ba.jpg)
Cantilever beam calculation [matlab code]

Machinery -- nx2007 (UG) finite element analysis tutorial 2 -- assembly

清洁、对话、带娃,扫地机摆脱“人工智障”标签

How to seamlessly transition from traditional microservice framework to service grid ASM

The first technology podcast month will be launched soon

Application of pointer in STC89C52 single chip microcomputer and demonstration of practical cases

The first unlucky person watching eth 2.0

利用tsne将不同句子关于相似度可视化出来

如何拒绝期末复习无用功?猿辅导:找准适合自己的复习方法很重要
随机推荐
Mysql 监控1
ctfshow 大赛原题 680-695
Tetris game based on STM32F103
[MRCTF2020]Ezpop-1|php序列化
Pytroch Learning Notes 6: NN network layer convolution layer
利用tsne将不同句子关于相似度可视化出来
Text classification using huggingface
Ansible ad-hoc 临时命令
存储引擎分析
Seata 与三大平台携手编程之夏,百万奖金等你来拿
[Thesis Writing] English thesis writing guide
数字垃圾是什么?跟随世界第一位AI艺术家,探索元碳艺术
Sentinel source code analysis Chapter 9 - core process - lookprocesschain finding resource processing chain
Internal class usage scenarios, syntax and principle explanations
如何拒绝期末复习无用功?猿辅导:找准适合自己的复习方法很重要
Using tsne to visualize the similarity of different sentences
Taguchi experimental method
Interview summary
Newton method (optimization of two variable functions)
【深度学习编译】算子编译 IR 转换