Ansible从入门到精通【二】

news2024/11/28 0:55:10

大家好,我是早九晚十二,目前是做运维相关的工作。写博客是为了积累,希望大家一起进步!
我的主页:早九晚十二
专栏名称:Ansible从入门到精通 立志成为ansible大佬

文章目录

    • ansible常用命令
      • ansible
      • ansible-doc命令
    • ansible-playbook
    • ansible-vault
    • ansible-console
    • ansible-galaxy
    • ansible的Host-pattern格式
    • ansible的命令执行过程
    • ansible的模块使用
      • Command
      • shell模块
      • Script模块
      • copy模块
      • fetch模块
      • file模块
      • hostname
      • cron
      • yum
      • service
      • user
      • group

请添加图片描述
今天主要是ansible的基本命令学习,ansible内置了1000+模块,每个模块都可以看做成是一个命令,而且参数各不相同,导致ansible的使用方法多种多样。
我们主要是学习一些常用的命令。

ansible常用命令

ansible

ansible命令是最主要的命令,我们在使用ansible执行任务时都需要这个指令。通过ssh实现配置管理、应用部署、任务执行等功能,建议配置ansible端能基于密钥认证的方式联系各被管理节点。

ansible <host-pattern> [-m module_name] [-a args]
--version 显示版本
-m module 指定模块,默认为command
-v 详细过程 -vv -vVV更详细
--list-hosts 显示主机列表,可简写-list
-k,--ask-pass提示输入ssh连接密码,默认Key验证-K,--ask-become-pass 提示输入sudo时的口令
-C,--check 检查,并不执行
-T,--timeout=TIMEOUT 执行命令的超时时间,默认10s
-u,--user=REMOTE_USER 执行远程执行的用户
-b,--become 代替日版的sudo 切换

示例

#例如,使用ansible调用ping命令联通测试机
#all代表所有主机,也可以单独指定主机分组,或者ip,主机名等
[root@0033 .ssh]# ansible all -m ping
192.168.0.226 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
#查看测试机的/boot目录
[root@0033 .ssh]# ansible all -m command -a "ls /boot"
192.168.0.226 | CHANGED | rc=0 >>
config-3.10.0-1160.90.1.el7.x86_64
config-3.10.0-1160.el7.x86_64
efi
grub
grub2
initramfs-0-rescue-98b448c3b99a45858a2edfd7aab282fb.img
initramfs-3.10.0-1160.90.1.el7.x86_64.img
initramfs-3.10.0-1160.90.1.el7.x86_64kdump.img
initramfs-3.10.0-1160.el7.x86_64.img
initramfs-3.10.0-1160.el7.x86_64kdump.img
symvers-3.10.0-1160.90.1.el7.x86_64.gz
symvers-3.10.0-1160.el7.x86_64.gz
System.map-3.10.0-1160.90.1.el7.x86_64
System.map-3.10.0-1160.el7.x86_64
vmlinuz-0-rescue-98b448c3b99a45858a2edfd7aab282fb
vmlinuz-3.10.0-1160.90.1.el7.x86_64
vmlinuz-3.10.0-1160.el7.x86_64

#查看ansible版本
[root@0033 .ssh]# ansible --version
ansible 2.9.27
  config file = /etc/ansible/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)]

#使用详细信息查看执行结果 -v -vv -vvv
[root@0033 .ssh]# ansible all -m command -a "ls /boot" -v
Using /etc/ansible/ansible.cfg as config file
192.168.0.226 | CHANGED | rc=0 >>
config-3.10.0-1160.90.1.el7.x86_64
config-3.10.0-1160.el7.x86_64
efi
grub
grub2
initramfs-0-rescue-98b448c3b99a45858a2edfd7aab282fb.img
initramfs-3.10.0-1160.90.1.el7.x86_64.img
initramfs-3.10.0-1160.90.1.el7.x86_64kdump.img
initramfs-3.10.0-1160.el7.x86_64.img
initramfs-3.10.0-1160.el7.x86_64kdump.img
symvers-3.10.0-1160.90.1.el7.x86_64.gz
symvers-3.10.0-1160.el7.x86_64.gz
System.map-3.10.0-1160.90.1.el7.x86_64
System.map-3.10.0-1160.el7.x86_64
vmlinuz-0-rescue-98b448c3b99a45858a2edfd7aab282fb
vmlinuz-3.10.0-1160.90.1.el7.x86_64
vmlinuz-3.10.0-1160.el7.x86_64
[root@0033 .ssh]# ansible all -m command -a "ls /boot" -vv
ansible 2.9.27
  config file = /etc/ansible/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)]
Using /etc/ansible/ansible.cfg as config file
Skipping callback 'actionable', as we already have a stdout callback.
Skipping callback 'counter_enabled', as we already have a stdout callback.
Skipping callback 'debug', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'full_skip', as we already have a stdout callback.
Skipping callback 'json', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'null', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Skipping callback 'selective', as we already have a stdout callback.
Skipping callback 'skippy', as we already have a stdout callback.
Skipping callback 'stderr', as we already have a stdout callback.
Skipping callback 'unixy', as we already have a stdout callback.
Skipping callback 'yaml', as we already have a stdout callback.
META: ran handlers
192.168.0.226 | CHANGED | rc=0 >>
config-3.10.0-1160.90.1.el7.x86_64
config-3.10.0-1160.el7.x86_64
efi
grub
grub2
initramfs-0-rescue-98b448c3b99a45858a2edfd7aab282fb.img
initramfs-3.10.0-1160.90.1.el7.x86_64.img
initramfs-3.10.0-1160.90.1.el7.x86_64kdump.img
initramfs-3.10.0-1160.el7.x86_64.img
initramfs-3.10.0-1160.el7.x86_64kdump.img
symvers-3.10.0-1160.90.1.el7.x86_64.gz
symvers-3.10.0-1160.el7.x86_64.gz
System.map-3.10.0-1160.90.1.el7.x86_64
System.map-3.10.0-1160.el7.x86_64
vmlinuz-0-rescue-98b448c3b99a45858a2edfd7aab282fb
vmlinuz-3.10.0-1160.90.1.el7.x86_64
vmlinuz-3.10.0-1160.el7.x86_64
META: ran handlers
META: ran handlers

ansible-doc命令

ansible-doc命令等于linux中的man命令,主要是查看各个模块的使用方法。该命令是按页展示,支持左右方向键翻看。

ansible-doc [options] [module....]
-a   显示所有模块的文档
-l, --list列出可用模块
-s,--snippet显示指定模块的playbook片段
示例:
ansible-doc -1 列出所有模块
ansible-doc ping 查看指定模块帮助用法
ansible-doc-s ping 查看指定模块帮助用法

示例

[root@0033 .ssh]# ansible-doc ping
> PING    (/usr/lib/python2.7/site-packages/ansible/modules/system/ping.py)

        A trivial test module, this module always returns `pong' on successful contact. It does not make sense in playbooks, but it is
        useful from `/usr/bin/ansible' to verify the ability to login and that a usable Python is configured. This is NOT ICMP ping,
        this is just a trivial test module that requires Python on the remote-node. For Windows targets, use the [win_ping] module
        instead. For Network targets, use the [net_ping] module instead.

  * This module is maintained by The Ansible Core Team
OPTIONS (= is mandatory):

- data
        Data to return for the `ping' return value.
        If this parameter is set to `crash', the module will cause an exception.
        [Default: pong]
        type: str


SEE ALSO:
      * Module net_ping
           The official documentation on the net_ping module.
           https://docs.ansible.com/ansible/2.9/modules/net_ping_module.html
      * Module win_ping
           The official documentation on the win_ping module.
           https://docs.ansible.com/ansible/2.9/modules/win_ping_module.html


AUTHOR: Ansible Core Team, Michael DeHaan
        METADATA:
          status:
          - stableinterface
          supported_by: core
        
:



#查看简易说明
[root@0033 ~]# ansible-doc -s ping
- name: Try to connect to host, verify a usable python and return `pong' on success
  ping:
      data:                  # Data to return for the `ping' return value. If this parameter is set to `crash', the module will cause an exception.

ansible-playbook

ansible-playbook是执行ansible剧本的命令,这个会在后面学习。

ansible-vault

文件加密工具,主要是保证主机名密码等隐私信息的安全。

ansible-console

基于Console界面与用户交互的执行工具

ansible-galaxy

下载/上传优秀代码或Roles模块的官网平台

ansible的Host-pattern格式

ansible的执行支持*通配符,例如

[root@0033 ~]# ansible 192.168.0.* -m ping
192.168.0.226 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

[root@0033 ~]# ansible "*" -m ping
192.168.0.226 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

[root@0033 ~]# ansible "t*" -m ping
192.168.0.226 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

支持或与运算

ansible “websrvs;appsrvs” -m ping
ansible “192.168.1.10:192.168.1.20”-m ping

ansible的命令执行过程

1.加载自己的配置文件 默认/etc/ansible/ansible.cfg
2.加载自己对应的模块文件,如command
3.通过ansible将模块或命令生成对应的临时py文件,并将该 文件传输至远程服务器的对应执行用户SHOME/.ansible/tmp/ansible-tmp-数字/XXX.PY文件
4.给文件+x执行
5.执行并返回结果
6.删除临时py文件,sleep o退出
执行状态 :
绿色: 执行成功并且不需要做改变的操作
黄色: 执行成功并且对目标主机做变更
红色: 执行失败

ansible的模块使用

Command

:在远程主机执行命令,默认模块,可忽略-m选项,如上面测试的ping指令

[root@0033 ~]# ansible "*" -m ping
192.168.0.226 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

但是command并不支持复杂运算, 如SVARNAME< > | ;& 等;
参考以下指令,command模块会将echo执行成输出指令。

[root@0033 ~]# ansible all -m command -a 'echo test lpasswd --stdin wang'
192.168.0.226 | CHANGED | rc=0 >>
testlpasswd --stdin wang

shell模块

支持复杂运算,比command更高级,但是更为复杂的指令还是适用性不太好

[root@0033 ~]# ansible all -m shell -a 'echo test lpasswd --stdin wang'
192.168.0.226 | CHANGED | rc=0 >>
test lpasswd --stdin wang

Script模块

调用bash执行命令类似 cat /tmp/stanley.md|awk -F’print S1,S2&>/tmp/example.txt 这些复杂命令,即使使用shell也可能会失败,解决办法: 写到脚本时,copy到远程,执行,再把需要的结果拉回执行命令的机器
Script : 运行脚本(自动复制脚本到其他机器)

[root@0033 ~]# ansible all -m script -a './name.sh'
192.168.0.226 | CHANGED => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 192.168.0.226 closed.\r\n", 
    "stderr_lines": [
        "Shared connection to 192.168.0.226 closed."
    ], 
    "stdout": "0037\r\n", 
    "stdout_lines": [
        "0037"
    ]
}

copy模块

将文件复制到其他机器上(开启备份功能)

[root@0033 ~]# ansible all -m copy -a 'src=/root/1.sh dest=/root  backup=yes'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "checksum": "f8615eade69d89da6d00670ff9b1b9085bd0054f", 
    "dest": "/root/1.sh", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "ccdc5a05c6d775679b93ee275980a58f", 
    "mode": "0644", 
    "owner": "root", 
    "size": 112, 
    "src": "/root/.ansible/tmp/ansible-tmp-1685071112.05-21576-269891096851158/source", 
    "state": "file", 
    "uid": 0
}

查看测试机是否有这个文件

[root@0033 ~]# ansible all -a 'ls /root/1.sh'
192.168.0.226 | CHANGED | rc=0 >>
/root/1.sh

fetch模块

从目标服务器抓取文件到主控机上

[root@0033 ~]# ansible all -m fetch -a 'src=/root/2.txt dest=/root'
192.168.0.226 | CHANGED => {
    "changed": true, 
    "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", 
    "dest": "/root/192.168.0.226/root/2.txt", 
    "md5sum": "d41d8cd98f00b204e9800998ecf8427e", 
    "remote_checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", 
    "remote_md5sum": null
}
[root@0033 ~]# ll 192.168.0.226/root/2.txt 
-rw-r--r-- 1 root root 0 May 26 11:33 192.168.0.226/root/2.txt
[root@0033 ~]# ansible all -m fetch -a 'src=/root/2.txt dest=/root'
192.168.0.226 | CHANGED => {
    "changed": true, 
    "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", 
    "dest": "/root/192.168.0.226/root/2.txt", 
    "md5sum": "d41d8cd98f00b204e9800998ecf8427e", 
    "remote_checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", 
    "remote_md5sum": null
}
[root@0033 ~]# ls
111.sh  192.168.0.226  1.sh  grafana-8.2.0-1.x86_64.rpm  grafana-8.3.0-1.x86_64.rpm  name.sh
[root@0033 ~]# ll 192.168.0.226/root/2.txt 
-rw-r--r-- 1 root root 0 May 26 11:33 192.168.0.226/root/2.txt

#fetch目前只能支持单一文件,如果需要多个文件需要压缩
[root@0033 ~]# ansible all -m shell -a 'tar Jcf log.tar.xz /var/log/*.log'
[WARNING]: Consider using the unarchive module rather than running 'tar'.  If you need to use command because unarchive is insufficient you can add 'warn: false' to this
command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.
192.168.0.226 | CHANGED | rc=0 >>
tar: Removing leading `/' from member names
[root@0033 ~]# ansible all -m shell -a 'ls /root'
192.168.0.226 | CHANGED | rc=0 >>
1.sh
2.txt
log.tar.xz
[root@0033 ~]# ansible all -m shell -a 'du -sh  /root/log.tar.xz'
192.168.0.226 | CHANGED | rc=0 >>
12K	/root/log.tar.xz

file模块

对文件夹或者文件进行操作
文件操作

#创建一个test2文件
[root@0033 ~]# ansible all  -m file -a 'name=/root/test1 state=touch'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "dest": "/root/test1", 
    "gid": 0, 
    "group": "root", 
    "mode": "0644", 
    "owner": "root", 
    "size": 0, 
    "state": "file", 
    "uid": 0
}
[root@0033 ~]# ansible all  -a 'ls -l /root/test1'
192.168.0.226 | CHANGED | rc=0 >>
-rw-r--r-- 1 root root 0 May 26 13:59 /root/test

#删除test2文件
[root@0033 ~]# ansible all  -m file -a 'name=/root/test1 state=absent'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "path": "/root/test1", 
    "state": "absent"
}
[root@0033 ~]# ansible all  -a 'ls -l /root/test1'
192.168.0.226 | FAILED | rc=2 >>
ls: cannot access /root/test1: No such file or directorynon-zero return code

文件夹操作

#创建dir文件夹
[root@0033 ~]# ansible all  -m file -a 'name=/root/dir1 state=directory'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "gid": 0, 
    "group": "root", 
    "mode": "0755", 
    "owner": "root", 
    "path": "/root/dir1", 
    "size": 4096, 
    "state": "directory", 
    "uid": 0
}
[root@0033 ~]# ansible all  -a 'ls -l /root/'
192.168.0.226 | CHANGED | rc=0 >>
total 20
-rw-r--r-- 1 root root   112 May 26 11:18 1.sh
-rw-r--r-- 1 root root     0 May 26 11:32 2.txt
drwxr-xr-x 2 root root  4096 May 26 14:02 dir1
-rw-r--r-- 1 root root 11508 May 26 12:01 log.tar.xz
#删除dir1文件夹
[root@0033 ~]# ansible all  -m file -a 'name=/root/dir1 state=absent'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "path": "/root/dir1", 
    "state": "absent"
}
[root@0033 ~]# ansible all  -a 'ls -l /root/'
192.168.0.226 | CHANGED | rc=0 >>
total 16
-rw-r--r-- 1 root root   112 May 26 11:18 1.sh
-rw-r--r-- 1 root root     0 May 26 11:32 2.txt
-rw-r--r-- 1 root root 11508 May 26 12:01 log.tar.xz

软连接操作

#创建
[root@0033 ~]# ansible all -m file -a 'src=/etc/fstab dest=/root/fstab.link state=link'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "dest": "/root/fstab.link", 
    "gid": 0, 
    "group": "root", 
    "mode": "0777", 
    "owner": "root", 
    "size": 10, 
    "src": "/etc/fstab", 
    "state": "link", 
    "uid": 0
}
[root@0033 ~]# ansible all  -a 'ls -l /root/'
192.168.0.226 | CHANGED | rc=0 >>
total 16
-rw-r--r-- 1 root root   112 May 26 11:18 1.sh
-rw-r--r-- 1 root root     0 May 26 11:32 2.txt
lrwxrwxrwx 1 root root    10 May 26 14:06 fstab.link -> /etc/fstab
-rw-r--r-- 1 root root 11508 May 26 12:01 log.tar.xz


#删除
[root@0033 ~]# ansible all -m file -a 'dest=/root/fstab.link state=absent'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "path": "/root/fstab.link", 
    "state": "absent"
}
[root@0033 ~]# ansible all  -a 'ls -l /root/'
192.168.0.226 | CHANGED | rc=0 >>
total 16
-rw-r--r-- 1 root root   112 May 26 11:18 1.sh
-rw-r--r-- 1 root root     0 May 26 11:32 2.txt
-rw-r--r-- 1 root root 11508 May 26 12:01 log.tar.xz

hostname

管理主机名

[root@0033 ~]# ansible 192.168.0.226 -m hostname -a 'name=test'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "ansible_domain": "", 
        "ansible_fqdn": "test", 
        "ansible_hostname": "test", 
        "ansible_nodename": "test", 
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "name": "test"
}
[root@0033 ~]# ansible 192.168.0.226 -a 'hostname'
192.168.0.226 | CHANGED | rc=0 >>
test

cron

计划任务模块

创建一个计划任务

[root@0033 ~]# ansible all -m cron -a 'minute=* weekday=1,3,5 job="/usr/bin/wall warning" name=warningcron'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "envs": [], 
    "jobs": [
        "warningcron"
    ]
}
[root@0033 ~]# ansible all -a 'crontab -l'
192.168.0.226 | CHANGED | rc=0 >>
#Ansible: warningcron
* * * * 1,3,5 /usr/bin/wall warning
[root@0033 ~]# 

禁用计划任务(如果开启将disabled改为false即可,yes、no也可)

[root@0033 ~]# ansible all -m cron -a 'disabled=true job="/usr/bin/wall warning" name=warningcron'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "envs": [], 
    "jobs": [
        "warningcron"
    ]
}
[root@0033 ~]# ansible all -a 'crontab -l'
192.168.0.226 | CHANGED | rc=0 >>
#Ansible: warningcron
#* * * * * /usr/bin/wall warnin

删除一个计划任务

[root@0033 ~]# ansible all -m cron -a 'job="/usr/bin/wall warning" name=warningcron state=absent'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "envs": [], 
    "jobs": []
}
[root@0033 ~]# ansible all -a 'crontab -l'
192.168.0.226 | CHANGED | rc=0 >>

yum

yum在线安装模块

[root@0033 ~]# ansible all -m yum -a 'name=vsftpd'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "changes": {
        "installed": [
            "vsftpd"
        ]
    }, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\nResolving Dependencies\n--> Running transaction check\n---> Package vsftpd.x86_64 0:3.0.2-29.el7_9 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package         Arch            Version                 Repository        Size\n================================================================================\nInstalling:\n vsftpd          x86_64          3.0.2-29.el7_9          updates          173 k\n\nTransaction Summary\n================================================================================\nInstall  1 Package\n\nTotal download size: 173 k\nInstalled size: 353 k\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Installing : vsftpd-3.0.2-29.el7_9.x86_64                                 1/1 \n  Verifying  : vsftpd-3.0.2-29.el7_9.x86_64                                 1/1 \n\nInstalled:\n  vsftpd.x86_64 0:3.0.2-29.el7_9                                                \n\nComplete!\n"
    ]
}
[root@0033 ~]# ansible all -m shell -a 'rpm -qa|grep vsftpd'
[WARNING]: Consider using the yum, dnf or zypper module rather than running 'rpm'.  If you need to use command because yum, dnf or zypper is insufficient you can add
'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.
192.168.0.226 | CHANGED | rc=0 >>
vsftpd-3.0.2-29.el7_9.x86_64

查看所有安装的包

[root@0033 ~]# ansible all -m yum -a 'list=installed'

卸载一个模块

[root@0033 ~]# ansible all -m yum -a 'name=vsftpd state=removed'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "changes": {
        "removed": [
            "vsftpd"
        ]
    }, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nResolving Dependencies\n--> Running transaction check\n---> Package vsftpd.x86_64 0:3.0.2-29.el7_9 will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package        Arch           Version                   Repository        Size\n================================================================================\nRemoving:\n vsftpd         x86_64         3.0.2-29.el7_9            @updates         353 k\n\nTransaction Summary\n================================================================================\nRemove  1 Package\n\nInstalled size: 353 k\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Erasing    : vsftpd-3.0.2-29.el7_9.x86_64                                 1/1 \n  Verifying  : vsftpd-3.0.2-29.el7_9.x86_64                                 1/1 \n\nRemoved:\n  vsftpd.x86_64 0:3.0.2-29.el7_9                                                \n\nComplete!\n"
    ]
}
[root@0033 ~]# ansible all -m shell -a 'rpm -qa|grep vsftpd'
[WARNING]: Consider using the yum, dnf or zypper module rather than running 'rpm'.  If you need to use command because yum, dnf or zypper is insufficient you can add
'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.
192.168.0.226 | FAILED | rc=1 >>
non-zero return code

安装多个包

[root@0033 ~]# ansible all -m yum -a 'name=vsftpd,nginx,httpd'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "changes": {
        "installed": [
            "vsftpd", 
            "nginx", 
            "httpd"
        ]
    }, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.4.6-98.el7.centos.7 will be installed\n--> Processing Dependency: httpd-tools = 2.4.6-98.el7.centos.7 for package: httpd-2.4.6-98.el7.centos.7.x86_64\n--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-98.el7.centos.7.x86_64\n--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-98.el7.centos.7.x86_64\n--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-98.el7.centos.7.x86_64\n---> Package nginx.x86_64 1:1.20.1-10.el7 will be installed\n--> Processing Dependency: nginx-filesystem = 1:1.20.1-10.el7 for package: 1:nginx-1.20.1-10.el7.x86_64\n--> Processing Dependency: libcrypto.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64\n--> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64\n--> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_1)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64\n--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.20.1-10.el7.x86_64\n--> Processing Dependency: redhat-indexhtml for package: 1:nginx-1.20.1-10.el7.x86_64\n--> Processing Dependency: libcrypto.so.1.1()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64\n--> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64\n--> Processing Dependency: libssl.so.1.1()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64\n---> Package vsftpd.x86_64 0:3.0.2-29.el7_9 will be installed\n--> Running transaction check\n---> Package apr.x86_64 0:1.4.8-7.el7 will be installed\n---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed\n---> Package centos-indexhtml.noarch 0:7-9.el7.centos will be installed\n---> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed\n---> Package httpd-tools.x86_64 0:2.4.6-98.el7.centos.7 will be installed\n---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed\n---> Package nginx-filesystem.noarch 1:1.20.1-10.el7 will be installed\n---> Package openssl11-libs.x86_64 1:1.1.1k-5.el7 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package              Arch       Version                      Repository   Size\n================================================================================\nInstalling:\n httpd                x86_64     2.4.6-98.el7.centos.7        updates     2.7 M\n nginx                x86_64     1:1.20.1-10.el7              epel        588 k\n vsftpd               x86_64     3.0.2-29.el7_9               updates     173 k\nInstalling for dependencies:\n apr                  x86_64     1.4.8-7.el7                  base        104 k\n apr-util             x86_64     1.5.2-6.el7                  base         92 k\n centos-indexhtml     noarch     7-9.el7.centos               base         92 k\n gperftools-libs      x86_64     2.6.1-1.el7                  base        272 k\n httpd-tools          x86_64     2.4.6-98.el7.centos.7        updates      94 k\n mailcap              noarch     2.1.41-2.el7                 base         31 k\n nginx-filesystem     noarch     1:1.20.1-10.el7              epel         24 k\n openssl11-libs       x86_64     1:1.1.1k-5.el7               epel        1.5 M\n\nTransaction Summary\n================================================================================\nInstall  3 Packages (+8 Dependent packages)\n\nTotal download size: 5.6 M\nInstalled size: 17 M\nDownloading packages:\n--------------------------------------------------------------------------------\nTotal                                               11 MB/s | 5.6 MB  00:00     \nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Installing : apr-1.4.8-7.el7.x86_64                                      1/11 \n  Installing : apr-util-1.5.2-6.el7.x86_64                                 2/11 \n  Installing : httpd-tools-2.4.6-98.el7.centos.7.x86_64                    3/11 \n  Installing : 1:openssl11-libs-1.1.1k-5.el7.x86_64                        4/11 \n  Installing : 1:nginx-filesystem-1.20.1-10.el7.noarch                     5/11 \n  Installing : gperftools-libs-2.6.1-1.el7.x86_64                          6/11 \n  Installing : mailcap-2.1.41-2.el7.noarch                                 7/11 \n  Installing : centos-indexhtml-7-9.el7.centos.noarch                      8/11 \n  Installing : 1:nginx-1.20.1-10.el7.x86_64                                9/11 \n  Installing : httpd-2.4.6-98.el7.centos.7.x86_64                         10/11 \n  Installing : vsftpd-3.0.2-29.el7_9.x86_64                               11/11 \n  Verifying  : httpd-tools-2.4.6-98.el7.centos.7.x86_64                    1/11 \n  Verifying  : centos-indexhtml-7-9.el7.centos.noarch                      2/11 \n  Verifying  : mailcap-2.1.41-2.el7.noarch                                 3/11 \n  Verifying  : apr-1.4.8-7.el7.x86_64                                      4/11 \n  Verifying  : apr-util-1.5.2-6.el7.x86_64                                 5/11 \n  Verifying  : gperftools-libs-2.6.1-1.el7.x86_64                          6/11 \n  Verifying  : 1:nginx-filesystem-1.20.1-10.el7.noarch                     7/11 \n  Verifying  : vsftpd-3.0.2-29.el7_9.x86_64                                8/11 \n  Verifying  : httpd-2.4.6-98.el7.centos.7.x86_64                          9/11 \n  Verifying  : 1:openssl11-libs-1.1.1k-5.el7.x86_64                       10/11 \n  Verifying  : 1:nginx-1.20.1-10.el7.x86_64                               11/11 \n\nInstalled:\n  httpd.x86_64 0:2.4.6-98.el7.centos.7       nginx.x86_64 1:1.20.1-10.el7      \n  vsftpd.x86_64 0:3.0.2-29.el7_9            \n\nDependency Installed:\n  apr.x86_64 0:1.4.8-7.el7                                                      \n  apr-util.x86_64 0:1.5.2-6.el7                                                 \n  centos-indexhtml.noarch 0:7-9.el7.centos                                      \n  gperftools-libs.x86_64 0:2.6.1-1.el7                                          \n  httpd-tools.x86_64 0:2.4.6-98.el7.centos.7                                    \n  mailcap.noarch 0:2.1.41-2.el7                                                 \n  nginx-filesystem.noarch 1:1.20.1-10.el7                                       \n  openssl11-libs.x86_64 1:1.1.1k-5.el7                                          \n\nComplete!\n"
    ]
}

卸载多个服务

[root@0033 ~]# ansible all -m yum -a 'name=vsftpd,nginx,httpd state=removed'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "changes": {
        "removed": [
            "vsftpd", 
            "nginx", 
            "httpd"
        ]
    }, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.4.6-98.el7.centos.7 will be erased\n---> Package nginx.x86_64 1:1.20.1-10.el7 will be erased\n---> Package vsftpd.x86_64 0:3.0.2-29.el7_9 will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package       Arch          Version                      Repository       Size\n================================================================================\nRemoving:\n httpd         x86_64        2.4.6-98.el7.centos.7        @updates        9.4 M\n nginx         x86_64        1:1.20.1-10.el7              @epel           1.7 M\n vsftpd        x86_64        3.0.2-29.el7_9               @updates        353 k\n\nTransaction Summary\n================================================================================\nRemove  3 Packages\n\nInstalled size: 11 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Erasing    : httpd-2.4.6-98.el7.centos.7.x86_64                           1/3 \n  Erasing    : 1:nginx-1.20.1-10.el7.x86_64                                 2/3 \n  Erasing    : vsftpd-3.0.2-29.el7_9.x86_64                                 3/3 \n  Verifying  : vsftpd-3.0.2-29.el7_9.x86_64                                 1/3 \n  Verifying  : httpd-2.4.6-98.el7.centos.7.x86_64                           2/3 \n  Verifying  : 1:nginx-1.20.1-10.el7.x86_64                                 3/3 \n\nRemoved:\n  httpd.x86_64 0:2.4.6-98.el7.centos.7       nginx.x86_64 1:1.20.1-10.el7      \n  vsftpd.x86_64 0:3.0.2-29.el7_9            \n\nComplete!\n"
    ]
}

如果是本地的rpm文件,可以先使用copy模块拷贝到其他机器,在使用yum模块指定name=rpm路径,即可

service

服务管理
启动vsftpd并且设置为开机自启动

[root@0033 ~]# ansible all -m service -a 'name=vsftpd state=started enabled=yes'
192.168.0.226 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "enabled": true, 
    "name": "vsftpd", 
    "state": "started", 
    "status": {
        "ActiveEnterTimestamp": "Fri 2023-05-26 15:47:33 CST", 
        "ActiveEnterTimestampMonotonic": "21333382495", 
        "ActiveExitTimestampMonotonic": "0", 
        "ActiveState": "active", 
        "After": "basic.target systemd-journald.socket network.target system.slice", 
        "AllowIsolate": "no", 
        "AmbientCapabilities": "0", 
        "AssertResult": "yes", 
        "AssertTimestamp": "Fri 2023-05-26 15:47:33 CST", 
        "AssertTimestampMonotonic": "21333379437", 
        "Before": "multi-user.target shutdown.target", 
        "BlockIOAccounting": "no", 
        "BlockIOWeight": "18446744073709551615", 
        "CPUAccounting": "no", 
        "CPUQuotaPerSecUSec": "infinity", 
        "CPUSchedulingPolicy": "0", 
        "CPUSchedulingPriority": "0", 
        "CPUSchedulingResetOnFork": "no", 
        "CPUShares": "18446744073709551615", 
        "CanIsolate": "no", 
        "CanReload": "no", 
        "CanStart": "yes", 
        "CanStop": "yes", 
        "CapabilityBoundingSet": "18446744073709551615", 
        "CollectMode": "inactive", 
        "ConditionResult": "yes", 
        "ConditionTimestamp": "Fri 2023-05-26 15:47:33 CST", 
        "ConditionTimestampMonotonic": "21333379437", 
        "Conflicts": "shutdown.target", 
        "ControlGroup": "/system.slice/vsftpd.service", 
        "ControlPID": "0", 
        "DefaultDependencies": "yes", 
        "Delegate": "no", 
        "Description": "Vsftpd ftp daemon", 
        "DevicePolicy": "auto", 
        "ExecMainCode": "0", 
        "ExecMainExitTimestampMonotonic": "0", 
        "ExecMainPID": "26430", 
        "ExecMainStartTimestamp": "Fri 2023-05-26 15:47:33 CST", 
        "ExecMainStartTimestampMonotonic": "21333382475", 
        "ExecMainStatus": "0", 
        "ExecStart": "{ path=/usr/sbin/vsftpd ; argv[]=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf ; ignore_errors=no ; start_time=[Fri 2023-05-26 15:47:33 CST] ; stop_time=[Fri 2023-05-26 15:47:33 CST] ; pid=26429 ; code=exited ; status=0 }", 
        "FailureAction": "none", 
        "FileDescriptorStoreMax": "0", 
        "FragmentPath": "/usr/lib/systemd/system/vsftpd.service", 
        "GuessMainPID": "yes", 
        "IOScheduling": "0", 
        "Id": "vsftpd.service", 
        "IgnoreOnIsolate": "no", 
        "IgnoreOnSnapshot": "no", 
        "IgnoreSIGPIPE": "yes", 
        "InactiveEnterTimestampMonotonic": "0", 
        "InactiveExitTimestamp": "Fri 2023-05-26 15:47:33 CST", 
        "InactiveExitTimestampMonotonic": "21333379806", 
        "JobTimeoutAction": "none", 
        "JobTimeoutUSec": "0", 
        "KillMode": "control-group", 
        "KillSignal": "15", 
        "LimitAS": "18446744073709551615", 
        "LimitCORE": "18446744073709551615", 
        "LimitCPU": "18446744073709551615", 
        "LimitDATA": "18446744073709551615", 
        "LimitFSIZE": "18446744073709551615", 
        "LimitLOCKS": "18446744073709551615", 
        "LimitMEMLOCK": "65536", 
        "LimitMSGQUEUE": "819200", 
        "LimitNICE": "0", 
        "LimitNOFILE": "4096", 
        "LimitNPROC": "63453", 
        "LimitRSS": "18446744073709551615", 
        "LimitRTPRIO": "0", 
        "LimitRTTIME": "18446744073709551615", 
        "LimitSIGPENDING": "63453", 
        "LimitSTACK": "18446744073709551615", 
        "LoadState": "loaded", 
        "MainPID": "26430", 
        "MemoryAccounting": "no", 
        "MemoryCurrent": "18446744073709551615", 
        "MemoryLimit": "18446744073709551615", 
        "MountFlags": "0", 
        "Names": "vsftpd.service", 
        "NeedDaemonReload": "no", 
        "Nice": "0", 
        "NoNewPrivileges": "no", 
        "NonBlocking": "no", 
        "NotifyAccess": "none", 
        "OOMScoreAdjust": "0", 
        "OnFailureJobMode": "replace", 
        "PermissionsStartOnly": "no", 
        "PrivateDevices": "no", 
        "PrivateNetwork": "no", 
        "PrivateTmp": "no", 
        "ProtectHome": "no", 
        "ProtectSystem": "no", 
        "RefuseManualStart": "no", 
        "RefuseManualStop": "no", 
        "RemainAfterExit": "no", 
        "Requires": "basic.target system.slice", 
        "Restart": "no", 
        "RestartUSec": "100ms", 
        "Result": "success", 
        "RootDirectoryStartOnly": "no", 
        "RuntimeDirectoryMode": "0755", 
        "SameProcessGroup": "no", 
        "SecureBits": "0", 
        "SendSIGHUP": "no", 
        "SendSIGKILL": "yes", 
        "Slice": "system.slice", 
        "StandardError": "inherit", 
        "StandardInput": "null", 
        "StandardOutput": "journal", 
        "StartLimitAction": "none", 
        "StartLimitBurst": "5", 
        "StartLimitInterval": "10000000", 
        "StartupBlockIOWeight": "18446744073709551615", 
        "StartupCPUShares": "18446744073709551615", 
        "StatusErrno": "0", 
        "StopWhenUnneeded": "no", 
        "SubState": "running", 
        "SyslogLevelPrefix": "yes", 
        "SyslogPriority": "30", 
        "SystemCallErrorNumber": "0", 
        "TTYReset": "no", 
        "TTYVHangup": "no", 
        "TTYVTDisallocate": "no", 
        "TasksAccounting": "no", 
        "TasksCurrent": "18446744073709551615", 
        "TasksMax": "18446744073709551615", 
        "TimeoutStartUSec": "1min 30s", 
        "TimeoutStopUSec": "1min 30s", 
        "TimerSlackNSec": "50000", 
        "Transient": "no", 
        "Type": "forking", 
        "UMask": "0022", 
        "UnitFilePreset": "disabled", 
        "UnitFileState": "enabled", 
        "WantedBy": "multi-user.target", 
        "WatchdogTimestamp": "Fri 2023-05-26 15:47:33 CST", 
        "WatchdogTimestampMonotonic": "21333382486", 
        "WatchdogUSec": "0"
    }
}
[root@0033 ~]# ansible all -m shell -a 'systemctl is-enabled vsftpd'
192.168.0.226 | CHANGED | rc=0 >>
enabled

同理,重启或者停止等,可以将state字段修改为reloaded, restarted, started, stopped等等,关闭自启动可以将enabled改为false或者no

user

用户管理
创建一个haha账号

#system表示是否为系统用户,home指定家目录,groups为附加组
[root@0033 ~]# ansible all -m user -a 'name=haha shell=/sbin/nologin system=yes home=/root/haha groups=root'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "append": false, 
    "changed": true, 
    "comment": "", 
    "group": 1000, 
    "groups": "root", 
    "home": "/root/haha", 
    "move_home": false, 
    "name": "haha", 
    "shell": "/sbin/nologin", 
    "state": "present", 
    "uid": 1000
}
[root@0033 ~]# ansible all -a 'getent passwd haha'
192.168.0.226 | CHANGED | rc=0 >>
haha:x:1000:1000::/root/haha:/sbin/nologin
[root@0033 ~]# ansible all -a 'ls -l /root'
192.168.0.226 | CHANGED | rc=0 >>
total 20
-rw-r--r-- 1 root root   112 May 26 11:18 1.sh
-rw-r--r-- 1 root root     0 May 26 11:32 2.txt
drwx------ 2 haha haha  4096 May 10 14:30 haha
-rw-r--r-- 1 root root 11508 May 26 12:01 log.tar.xz

删除haha账号与haha的家目录

[root@0033 ~]# ansible all -m user -a 'name=haha state=absent remove=yes'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, `在这里插入代码片`
    "changed": true, 
    "force": false, 
    "name": "haha", 
    "remove": true, 
    "state": "absent"
}
[root@0033 ~]# ansible all -a 'ls -l /root'
192.168.0.226 | CHANGED | rc=0 >>
total 16
-rw-r--r-- 1 root root   112 May 26 11:18 1.sh
-rw-r--r-- 1 root root     0 May 26 11:32 2.txt
-rw-r--r-- 1 root root 11508 May 26 12:01 log.tar.xz
[root@0033 ~]# ansible all -a 'getent passwd haha'
192.168.0.226 | FAILED | rc=2 >>
non-zero return code

group

组管理
创建哈哈的组

[root@0033 ~]# ansible all -m group -a 'name=haha system=yes gid=80'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "gid": 80, 
    "name": "haha", 
    "state": "present", 
    "system": true
}
[root@0033 ~]# ansible all -a 'getent group haha'
192.168.0.226 | CHANGED | rc=0 >>
haha:x:80:

删除组

[root@0033 ~]# ansible all -m group -a 'name=haha state=absent'
192.168.0.226 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "name": "haha", 
    "state": "absent"
}
[root@0033 ~]# ansible all -a 'getent group haha'
192.168.0.226 | FAILED | rc=2 >>
non-zero return code

码字不易。如果文章对您有希望的话,请三连支持一波。
如有问题,欢迎留言,一起探讨,感谢。
也可关注下方公众号,看到留言后会第一时间回复。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/573066.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Revit幕墙:用幕墙巧做屋面瓦及如何快速幕墙?

一、Revit中用幕墙巧做屋面瓦 屋面瓦重复性很高&#xff0c;我们如何快速的创建呢?下面我们来学会快速用幕墙来创建屋面瓦的技巧。 1.新建“公制轮廓-竖挺”族&#xff0c;以此来创建瓦的族(以便于载入项目中使用) 2.在轮廓族中绘制瓦的轮廓(轮廓需要闭合)&#xff0c;将族名称…

淘宝天猫618预售活动时间是从几号什么时候开始2023天猫淘宝618预售定金能退吗?

2023年淘宝天猫618预售什么时候开始&#xff1f; 2023年5月26日20:00淘宝天猫618预售活动开始截至到5月31日18:00结束&#xff1b; 2023年淘宝天猫618预售定金支付后可退吗&#xff1f; 淘宝天猫618预售定金支付后如不想要该预售商品了&#xff0c;可以在5月31日20:00后完成尾…

如何获得高清、4K无水印视频素材?教你轻松拥有高清视频

随着短视频越来越火爆&#xff0c;大家也都加入到了视频创作的行业中&#xff0c;平时也会喜欢剪辑一些视频发布到平台上&#xff0c;那高清的短视频肯定是最受欢迎的&#xff0c;我们自己又如何获得高清的视频呢&#xff1f; 一、为什么需要高清的视频素材&#xff1f; 1. 视…

基于非靶向和靶向代谢组学分析婴幼儿血管瘤的氨基酸代谢

文章标题&#xff1a;Integrated nontargeted and targeted metabolomics analyses amino acids metabolism in infantile hemangioma 发表期刊&#xff1a;Frontiers in Oncology 影响因子&#xff1a;5.738 作者单位&#xff1a;四川大学华西医院 百趣提供服务&#xf…

prometheus 部署安装

prometheus 部署安装 监控系统硬件&#xff08;node-exporter&#xff09;监控mysql &#xff08;mysql_exporter&#xff09;监控redis&#xff08;redis_exporter&#xff09;监控docker &#xff08;cadvisor&#xff09;监控可视化展示 (Grafana)监控报警 &#xff08;Ale…

Adams几何元素

简单学了一下Adams的几何元素&#xff0c;记录一下面板。 1.几何点 Point Add to Ground 添加到大地 Add to Part 添加到现有构件 Attach Near 关联构件 Don’t Attach 不关联构件 创建添加行&#xff0c;输入点坐标。创建好的点可以在导航栏右键删除和修改。 2. 坐标系Mar…

ROS学习——利用电脑相机标定

一、 安装usb-cam包和标定数据包 sudo apt-get install ros-kinetic-usb-cam sudo apt-get install ros-kinetic-camera-calibration 要把kinetic改成你自己的ros版本 。 二、启动相机 roslaunch usb_cam usb_cam-test.launch 就会出现一个界面 可以通过下面命令查看相机…

leetcode 1140. Stone Game II(石头游戏II)

涉及game的问题&#xff0c;2个player, 现有几堆石头&#xff0c;每堆石头个数为piles[i], 刚开始M1, player1先拿石头&#xff0c;可以拿走前 x 堆&#xff08;假设从第 i 堆开始拿&#xff0c;可以拿 i ~ ix-1 堆&#xff09;&#xff0c;1 < x < 2M, 拿完之后&#xf…

2023.5.19Hadoop具体操作(四种)

大作业 1、ens33没有地址 查看虚拟机的NAT8网段 使用ip a显示ens33的ip ip a设置静态ip 编辑网络接口配置文件&#xff1a;输入以下命令来编辑网络接口的配置文件&#xff1a; sudo vi /etc/network/interfaces在打开的文件中&#xff0c;找到要设置为静态IP的网络接口&am…

来领走你的AI老师

现在很多大学生不上课&#xff0c;在b站学习。 有没有想过有一天&#xff0c;你的大多数时间都在跟AI学习&#xff1f; 未来已来&#xff0c;这里有一份万能提示词&#xff0c;让你立马拥有一位AI导师。 这位导师可了不得&#xff0c;除了啥都知道之外&#xff0c;还能&…

C# 队列(Queue)

目录 一、概述 二、基本的用法 1.添加元素 2.取出元素 1&#xff09;Dequeue 方法 2&#xff09;Peek 方法 3.判断元素是否存在 4.获取队列的长度 5.遍历队列 6.清空容器 7.Queue 泛型类 三、结束 一、概述 表示对象的先进先出集合。 队列和其他的数据结构一样&a…

Ros2中MoveItConfigsBuilder的功能作用说明

文章目录 前言MoveItConfigsBuilder的功能作用机器人resource文件样例总结 前言 在学习moveit2的样例时发现加载机器人配置参数多使用MoveItConfigsBuilder&#xff0c;它具体的功能和使用方法是什么呢。 这篇博文用来记录说明该函数的使用方法、作用和调用逻辑。 MoveItConfi…

Tomcat的讲解与安装

文章目录 前言一.Tomcat是什么二.Tomcat的原理三.Tomcat的安装和说明**1.下载****2.解压安装**bin目录conf目录lib目录log目录temp目录webapps目录work目录 3.配置环境变量 四.验证安装 前言 Tomcat 是一个 HTTP 服务器. 前面我们已经学习了 HTTP 协议, 知道了 HTTP 协议就是 …

共享电单车RFID停车技术分析

近段时间&#xff0c;某地主城区运营商信号基站受严重干扰&#xff0c;造成300多个基站&#xff0c;超过5万的用户受到影响。据无线电监测站的调查确认干扰源来自共享电单车&#xff0c;是共享电单车加装的RFID停车标签惹的祸&#xff0c;而该地区RFID终端选用的是超高频&#…

考研C语言复习第二章

考研C语言第二节课 2.1 #include <stdio.h> //符号常量 #define PI 32 int main() {int iPI*2;printf("i%d\n",i); // printf("Hello, World!\n");return 0; }在这里的define相当于一个替换的作用&#xff0c;是直接将PI是32整个搬到下面 所以…

M洞察|“MOBA”还是“MMO”?2023上半年热门手游大盘点来了,拯救你的游戏荒

2023年Q1中国移动游戏市场整体表现不及预期&#xff0c;实际销售收入为486.94亿元&#xff0c;同比下降19.42%。虽整体有所下滑&#xff0c;但新鲜血液依然迸发强劲。 3月22日&#xff0c;一款玩法轻松、新颖的种田类手游《桃源深处有人家》正式上线&#xff0c;玩家纷纷投入其…

AWVS使用手册 (全)

目录 000、什么是Acunetix Web Vulnarability Scanner 001、AWVS安装过程、主要文件介绍、界面简介、主要操作区域简介 002、AWVS的菜单栏、工具栏简介&#xff08;AWVS menus bar & tools bar&#xff09; 003&#xff1a;一次新的扫描的功能全面概述&#xff08;Scan…

基于SpringBoot的企业客户信息反馈平台的设计与实现

背景 企业客户信息反馈平台能够通过互联网得到广泛的、全面的宣传&#xff0c;让尽可能多的用户了解和熟知企业客户信息反馈平台的便捷高效&#xff0c;不仅为客户提供了服务&#xff0c;而且也推广了自己&#xff0c;让更多的客户了解自己。对于企业客户信息反馈而言&#xf…

vue3+element-plus+ts elplus table 实现表格动态列 表格列显示与隐藏的动态控制

工作接了个需求&#xff0c;需要实现表格的动态列&#xff0c;但是后端又不参与&#xff0c;全权交给前端&#xff0c;百度搜了一下&#xff0c;大多都是el-table-column的for循环&#xff0c;我觉得用起来不爽&#xff0c;还得改变el-table-column的书写方式&#xff0c;用对象…

软考A计划-2022年05月软件设计师下午真题及答案解析

点击跳转专栏>Unity3D特效百例点击跳转专栏>案例项目实战源码点击跳转专栏>游戏脚本-辅助自动化点击跳转专栏>Android控件全解手册点击跳转专栏>Scratch编程案例 &#x1f449;关于作者 专注于Android/Unity和各种游戏开发技巧&#xff0c;以及各种资源分享&am…