当前位置:网站首页>Ansible cloud computing automation
Ansible cloud computing automation
2022-04-23 10:03:00 【Database from deleting database to running】
Four servers :
ansible: The management end
node01 node02 node03: Managed nodes
1) install
[root@ansible ~]# yum install ansible -y
2) view help
[root@ansible ~]# ansible-doc -l | wc -l # View the number of modules
[root@ansible ~]# ansible-doc -s yum # see yum Parameters of the module
[root@ansible ~]# ansible-doc yum # View relevant help information ( Search for /EXAMPLES)
[root@ansible ~]# ansible node03 -m setup # Get the built-in related variables of the opposite node ( Host name ip Address, etc )
3) How to view the detailed help information of a module
View the source code : /usr/lib/python2.7/site-packages/ansible/modules/packaging/os/yum.py
ansible-doc yum # View relevant help information ( Search for /EXAMPLES)
Four common modules :
yum copy file service
Several important concepts :
install present
uninstall absent
upgrade latest
exclude exclude
Designated warehouse enablerepo
Grammar format :
ansible Host name or group name -m Specify modules -a Specific commands
yum modular :
# Example 1: Install the latest apache Software , Update if it exists
[root@ansible ~]# ansible group1 -m yum -a "name=httpd state=latest"
# Example 2: Install the latest apache Software , Install through local warehouse
[root@ansible ~]# ansible group1 -m yum -a "name=httpd state=latest enablerepo=c7-local-http"
# Example 3: Delete apache Software
[root@ansible ~]# ansible group1 -m yum -a "name=httpd state=absent"
copy modular :
# Example 1: Local httpd.conf file Listen Port changed to 8080, Then push it to the remote server
[root@ansible ~]# ansible group1 -m copy -a "src=/etc/ansible/source_code/copy_module/httpd.conf dest=/etc/httpd/conf/httpd.conf owner=root group=root mode=644"
# Example 2: Local httpd.conf file Listen Port changed to 8088, Then push it to the far end , Check whether the last backup file exists at the remote end
[root@ansible ~]# ansible group1 -m copy -a "src=/etc/ansible/source_code/copy_module/httpd.conf dest=/etc/httpd/conf/httpd.conf owner=root group=root mode=644 backup=yes"
# Check whether there is a corresponding backup file
[root@ansible ~]# ssh node01 ls /etc/httpd/conf/httpd\*
# Example 3: Write content to the remote host file
[root@ansible ~]# ansible group1 -m copy -a "content='Hello World......\n' dest=/var/www/html/index.html"
# Verify whether the file content corresponding to the opposite server has been modified
[root@ansible ~]# ssh node01 cat /var/www/html/index.html
file modular :
# Example 1: create a file /var/www/html/hostname.html, And set the owner Generic group jurisdiction
[root@ansible ~]# ansible group1 -m file -a "path=/var/www/html/hostname.html state=touch owner=apache group=apache mode=644"
# Check whether the file was created successfully
[root@ansible copy_module]# ssh node01 ls -lt /var/www/html/hostname.html
# Example 2: Create directory /var/www/html/imgs, And set the owner Generic group jurisdiction
[root@ansible ~]# ansible group1 -m file -a "path=/var/www/html/imgs state=directory owner=apache group=apache mode=755"
[root@ansible ~]# ssh node01 ls -ld /var/www/html/imgs
# Example 3: Recursive authorization directory
[root@ansible ~]# ansible group1 -m file -a "path=/var/www/html/ owner=apache group=apache mode=755"
[root@ansible ~]# ansible group1 -m file -a "path=/var/www/html/ owner=apache group=apache recurse=yes" # Recursive Authorization
service modular :
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=stopped" # Stop service first
View service status :
[root@ansible ~]# ssh node01 systemctl status httpd | grep 'Active: '
Active: inactive (dead) since # stopped state
# Example 1: start-up Httpd service
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=started"
View service status :
[root@ansible ~]# ssh node01 systemctl status httpd | grep 'Active: '
Active: active (running) since Mon # running state
# Example 2: heavy load Httpd service
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=reloaded"
# Example 3: restart Httpd service
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=restarted"
# Example 4: stop it Httpd service
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=stopped"
# Example 5: start-up Httpd service , And add boot - up
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=started enabled=yes"
版权声明
本文为[Database from deleting database to running]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230956066938.html
边栏推荐
- 第一章 Oracle Database In-Memory 相关概念(续)(IM-1.2)
- Go语言实践模式 - 函数选项模式(Functional Options Pattern)
- F-niu Mei's apple tree (diameter combined)
- A concise course of fast Fourier transform FFT
- Solving Lucas number and combination theorem
- [2020wc Day2] F. Clarice picking mushrooms (subtree and query, light and heavy son thought)
- [hdu6868] absolute math (pusher + Mobius inversion)
- 中控学习型红外遥控模块支持网络和串口控制
- [codeforces - 208e] blood cousins
- 论文阅读《Integrity Monitoring Techniques for Vision Navigation Systems》——5结果
猜你喜欢
Cloud identity is too loose, opening the door for attackers
论文阅读《Integrity Monitoring Techniques for Vision Navigation Systems》——5结果
Sim Api User Guide(6)
面试官:说几个PHP常用函数,幸好我面试之前看到了这篇文章
Examination questions and answers of the third batch (main person in charge) of Guangdong safety officer a certificate in 2022
MapReduce核心和基础Demo
Nine abilities of agile manufacturing in the era of meta universe
正大国际讲解道琼斯工业指数到底是什么?
自定义登录失败处理
Career planning and implementation in the era of meta universe
随机推荐
通过流式数据集成实现数据价值(2)
Number theory blocking (integer division blocking)
[codeforces - 208e] blood cousins
Juc并发编程06——深入剖析队列同步器AQS源码
打印页面的功能实现
Chapter II in memory architecture (im-2.2)
failureForwardUrl与failureUrl
第二章 In-Memory 体系结构 (IM-2.2)
2022年广东省安全员A证第三批(主要负责人)考试试题及答案
深度选择器
Failureforwardurl and failureurl
Yarn核心参数配置
ansible playbook语法和格式 自动化云计算
Custom login failure handling
[hdu6833] a very easy math problem
C语言:表达式求值(整型提升、算术转换 ...)
SQL调优系列文章之—SQL调优简介
P1390 sum of common divisor (Mobius inversion)
SQL tuning series - SQL performance methodology
面试官:说几个PHP常用函数,幸好我面试之前看到了这篇文章