首页 > 其他分享 >Use Ansible-2.9.27 Modular on openEuler

Use Ansible-2.9.27 Modular on openEuler

时间:2022-11-27 17:44:28浏览次数:71  
标签:10.0 Use 27 ## Modular ansible 模块 1.51 root

一、Use Ansible-2.9.27 Modular  on openEuler

1 地址

 

2 ad-hoc 概述

ad-hoc是临时命令,执行完就结束了,可以执行简单的任务。如:临时批量查看被控制的机器版本进程拷贝等等。

命令格式:ansible    iyuyixyz    -m      command    -a       'cat /etc/openEuler-release'
格式说明:命令        主机名称    指定模块  模块名称  模块动作      执行命令

返回结果的颜色:绿色,黄色,红色,粉色。

3 ad-hoc模式的模块有

command
shell
scripts
yum
yum_repository
copy
file
mount
service
cron
iptables
firewalld
get_url

 

二、常用模块

1 command 模块

官方链接:https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html#ansible-collections-ansible-builtin-command-module

不支持管道及特殊符号,需使用 shell 模块

[root@manage ~]# ansible 10.0.1.51 -a 'df -h'
## 
[root@manage ~]# ansible 10.0.1.51 -a 'ip a |grep ens33'
[WARNING]: Platform linux on host 10.0.1.51 is using the discovered Python interpreter at
/usr/bin/python3, but future installation of another Python interpreter could change this.
See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for
more information.
10.0.1.51 | FAILED | rc=255 >>
Command "|grep" is unknown, try "ip address help".non-zero return code

2 shell 模块

## 
[root@manage ~]# ansible 10.0.1.51 -m shell -a 'ip a |grep ens33'
[WARNING]: Platform linux on host 10.0.1.51 is using the discovered Python interpreter at
/usr/bin/python3, but future installation of another Python interpreter could change this.
See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for
more information.
10.0.1.51 | CHANGED | rc=0 >>
3: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    inet 10.0.1.51/24 brd 10.0.1.255 scope global noprefixroute ens33

3 script模块

## 管理节点上创建一个脚本
cat > /opt/xyz.sh << EOF
touch /opt/xyz.txt
EOF
## 
chmod +x /opt/xyz.sh
## 
[root@manage ~]# ansible 10.0.1.51 -m script -a '/opt/xyz.sh'
10.0.1.51 | CHANGED => {
    "changed": true,
    "rc": 0,
    "stderr": "Shared connection to 10.0.1.51 closed.\r\n",
    "stderr_lines": [
        "Shared connection to 10.0.1.51 closed."
    ],
    "stdout": "",
    "stdout_lines": []
}
## 测试
[root@manage ~]# ansible 10.0.1.51 -m shell -a 'ls -l /opt'
[WARNING]: Platform linux on host 10.0.1.51 is using the discovered Python interpreter at
/usr/bin/python3, but future installation of another Python interpreter could change this.
See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for
more information.
10.0.1.51 | CHANGED | rc=0 >>
total 16
drwxr-xr-x. 2 rsyncxyz rsyncxyz 4096 Nov 24 14:31 backupxyz
drwxr-xr-x  3 root     root     4096 Nov 25 22:19 nfs
drwxr-xr-x. 2 root     root     4096 Nov 23 15:48 software
-rw-r--r--  1 root     root        0 Nov 27 17:10 xyz.txt

4 yum 模块

官方链接:https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html#ansible-collections-ansible-builtin-yum-module

yum 模块参数 说明
name 指定安装软件名字,可以安装多个软件
state 状态present 或者 installed 安装,absent或者removed删除,latest更新
exclude 安装软件时,可以排除
enablerepo 安装软件时临时开启被关闭的yum源
## 下载并安装
ansible 10.0.1.51 -m yun 'name=https://repo.openeuler.org/openEuler-22.09/everything/x86_64/Packages/httpd-2.4.51-11.oe2209.x86_64.rpm state=installed'
## 安装最新的httpd
ansible 10.0.1.51 -m yun 'name=httpd state=latest'
## 删除
ansible 10.0.1.51 -m yun 'name=tree state=removed'

 

 

 

 

 

 

 

 

 

X、One Step Success

 

1 帮助命令

## 查询模块
ansible-doc -l
## 查询某个模块
ansible-doc -s ping

## 查询有多少模块
ansible-doc -l | wc -l

 

Y、Error message

 

 

 

 

 

 

 

Z、Related Links

Installing Ansible-2.9.27 Inventory Use on openEuler:https://www.cnblogs.com/huaxiayuyi/p/16928621.html

 

标签:10.0,Use,27,##,Modular,ansible,模块,1.51,root
From: https://www.cnblogs.com/huaxiayuyi/p/16929863.html

相关文章

  • #MyBatis和MyBatis Plus学习之旅(200-11-27)
    Mybatis和MybatisPlus的jar包/maven文件Mybatis的jar包/maven文件1、jar包: ​​mybatis-x.x.x.jar​​ 2、maven文件:<!--spring的maven文件--><!--mybatis包--><dependen......
  • 介绍27款经典的CSS框架
    利用CSS框架,可以简化你的工作,提高工作效率。CSS框架是一系列CSS文件的集合体,包含了基本的元素重置,页面排版、网格布局、表单样式、通用规则等代码块。下面给你推荐了27......
  • IDEATomact Address localhost1099 is already in use
    Errorrunning'Tomcat9.0.19':Addresslocalhost:1099isalreadyinuse尝试解决第一步:查询被占用端口netstat-ano|findstr1099结果为空,尴尬,不是说inuse......
  • AtCoder Beginner Contest 279
    咕咕咕。D-Freefall三分求极值,注意下标得是整数,所以最后再搜索三分结果附近的整数。直接求导应该也可以。AC代码//#defineMULTIPLE_TASK#include"hira/main.cp......
  • 20221127周日Vue中message.split().reverse().join()函数用法
    Vue中message.split().reverse().join()函数用法 1、split('') 把一个字符串分割成字符串数组 把数据拆分为一个数组,括号里的''是把数据拆分为每个字符串2、r......
  • ClickHouse 学习02
    在ClickHouse中,一个表代表一个目录(文件夹),一个列就是一个文件......
  • Java.11.27
    一.方法的重载1.重载就是在一个类中,有相同的函数名称,但形参不同的函数。2.方法重载的规则:2.1.方法名称必须相同2.2.参数列表必须不同(个数不同......
  • 2278. 企鹅游行
    题目链接2278.企鹅游行在南极附近的某个地方,一些企鹅正站在一些浮冰上。作为群居动物,企鹅们喜欢聚在一起,因此,它们想在同一块浮冰上会合。企鹅们不想淋湿自己,所以它们......
  • 【ClickHouse 内核原理图文详解】关于分区、索引、标记和压缩数据的协同工作...
    概述ClickHouse是一个用于联机分析处理(OLAP)的列式数据库管理系统(ColumnarDBMS)。分区、索引、标记和压缩数据,这些组件配合在一起给ClickHouse数据库带来非常高效的查询......
  • 【ClickHouse】How to create index for Map Type Column or one key of it?
    HowtocreateindexforMapTypeColumnoronekeyofit?[version21.8.10revision54449]#31801Youcancreateindexformapkeys,orformapvalues.Example:C......