当前位置:网站首页>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
边栏推荐
- 2022年制冷与空调设备运行操作考试练习题及模拟考试
- DBA common SQL statements (3) - cache, undo, index and wait events
- LeetCode-608. 树节点
- 2022年广东省安全员A证第三批(主要负责人)考试试题及答案
- Integral function and Dirichlet convolution
- 正大国际讲解道琼斯工业指数到底是什么?
- Function realization of printing page
- Yarn资源调度器
- 2022 mobile crane driver test question bank simulation test platform operation
- 杰理之有时候发现内存被篡改,但是没有造成异常,应该如何查找?【篇】
猜你喜欢
Nine abilities of agile manufacturing in the era of meta universe
[untitled]
Computer network security experiment II DNS protocol vulnerability utilization experiment
Yarn核心参数配置
failureForwardUrl与failureUrl
一文看懂 LSTM(Long Short-Term Memory)
2022年上海市安全员C证考试题库及答案
【无标题】
2022茶艺师(初级)考试试题模拟考试平台操作
Career planning and implementation in the era of meta universe
随机推荐
第一章 Oracle Database In-Memory 相关概念(续)(IM-1.2)
2022年制冷与空调设备运行操作考试练习题及模拟考试
Explanation of order and primitive root of number theory
通过流式数据集成实现数据价值(3)- 实时持续数据收集
Formattime timestamp format conversion
杰理之有时候发现内存被篡改,但是没有造成异常,应该如何查找?【篇】
ansible 云计算 自动化
Longest common front string
Less than 100 secrets about prime numbers
formatTime时间戳格式转换
Depth selector
LeetCode 1249. Minimum Remove to Make Valid Parentheses - FB高频题1
转:毛姆:阅读是一座随身携带的避难所
DBA常用SQL语句(6)- 日常管理
Compile and debug mysql8 with clion under MacOS x
使用IDEA开发Spark程序
Introduction to graph theory -- drawing
MapReduce压缩
C语言:表达式求值(整型提升、算术转换 ...)
Computer network security experiment II DNS protocol vulnerability utilization experiment