当前位置: 首页 > news >正文

Ansible从入门到精通【六】

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

在这里插入图片描述

ansible templates

    • 模板(templates)的认识
      • 模板的使用方式
      • 模板的目录
      • 帮助文档
      • 使用模板管理nginx
      • 修改nginx的work数量
        • ansible cpu变量查看
        • 编辑模板文件
        • 修改template剧本
        • 再次执行
        • 查看配置文件是否读取变量
    • when的使用
      • 查看版本号
      • 执行剧本
      • 嵌套变量传递
      • FOR循环与条件判断
        • FOR循环
        • if判断

模板(templates)的认识

模板的使用方式

  1. 文本文件,嵌套有脚本(使用模板编程语言编写)
  2. jinja2语言,使用字面量,有下面形式
    字符串:使用单引号或者双引号
    数字:整数,浮点数
    列表:[item1,item2,…]
    元组;(item1,item2,…)
    字典:{key1:value1,key2:value2,…}
    布尔:true/false
  3. 算数运算:+,-,*,/,//,%,**
  4. 比较运算:==,!=,>,>=,<,<=
  5. 逻辑运算:and,or,not
  6. 流表达式:For If When

模板的目录

一般建议在ansible目录下创建templates目录,与playbook剧本平行

帮助文档

[root@zhaoyj ansible]# ansible-doc -s template
- name: Template a file out to a remote servertemplate:attributes:            # The attributes the resulting file or directory should have. To get supported flags look at the man page for `chattr' on the targetsystem. This string should contain the attributes in the same order as the one displayed by `lsattr'. The`=' operator is assumed as default, otherwise `+' or `-' operators need to be included in the string.backup:                # Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.block_end_string:      # The string marking the end of a block.block_start_string:    # The string marking the beginning of a block.dest:                  # (required) Location to render the template to on the remote machine.follow:                # Determine whether symbolic links should be followed. When set to `yes' symbolic links will be followed, if they exist. When set to `no'symbolic links will not be followed. Previous to Ansible 2.4, this was hardcoded as `yes'.force:                 # Determine when the file is being transferred if the destination already exists. When set to `yes', replace the remote file when contentsare different than the source. When set to `no', the file will only be transferred if the destination doesnot exist.group:                 # Name of the group that should own the file/directory, as would be fed to `chown'.lstrip_blocks:         # Determine when leading spaces and tabs should be stripped. When set to `yes' leading spaces and tabs are stripped from the start of aline to a block. This functionality requires Jinja 2.7 or newer.mode:                  # The permissions the resulting file or directory should have. For those used to `/usr/bin/chmod' remember that modes are actually octalnumbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number(like `0644' or `01777') or quote it (like `'644'' or `'1777'') so Ansible receives a string and can doits own conversion from string into number. Giving Ansible a number without following one of these ruleswill end up with a decimal number which will have unexpected results. As of Ansible 1.8, the mode may bespecified as a symbolic mode (for example, `u+rwx' or `u=rw,g=r,o=r').newline_sequence:      # Specify the newline sequence to use for templating files.output_encoding:       # Overrides the encoding used to write the template file defined by `dest'. It defaults to `utf-8', but any encoding supported by pythoncan be used. The source template file must always be encoded using `utf-8', for homogeneity.owner:                 # Name of the user that should own the file/directory, as would be fed to `chown'.selevel:               # The level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the `range'. When set to `_default', itwill use the `level' portion of the policy if available.serole:                # The role part of the SELinux file context. When set to `_default', it will use the `role' portion of the policy if available.

使用模板管理nginx

模拟一个nginx的模板文件

cp /etc/nginx/nginx.conf /root/ansible/templates/nginx.conf.j2

编写yml剧本

[root@zhaoyj ansible]# cat templates.yml 
---
- hosts: testremote_user: roottasks:- name: install pkgyum: name=nginx- name: copy templatetemplate: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf- name: start serviceservice: name=nginx state=started enabled=yes
...

测试yml

[root@zhaoyj ansible]# ansible-playbook -C templates.yml 

执行(这里报错了,是因为主控机有证书)

[root@zhaoyj ansible]# ansible-playbook  templates.yml PLAY [test] ***********************************************************************************************************************************************************************************************************TASK [Gathering Facts] ************************************************************************************************************************************************************************************************
ok: [192.168.6.249]TASK [install pkg] ****************************************************************************************************************************************************************************************************
changed: [192.168.6.249]TASK [copy template] **************************************************************************************************************************************************************************************************
changed: [192.168.6.249]TASK [start service] **************************************************************************************************************************************************************************************************
fatal: [192.168.6.249]: FAILED! => {"changed": false, "msg": "Unable to start service nginx: Job for nginx.service failed because the control process exited with error code. See \"systemctl status nginx.service\" and \"journalctl -xe\" for details.\n"}PLAY RECAP ************************************************************************************************************************************************************************************************************
192.168.6.249              : ok=3    changed=2    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

修改nginx的work数量

修改nginx的work数量,根据实际的cpu生成

ansible cpu变量查看

[root@zhaoyj ansible]# ansible test -m setup |grep "cpu""ansible_processor_vcpus": 8, 

编辑模板文件

[root@zhaoyj templates]# vim nginx.conf.j2 user  nginx;
worker_processes  {{ ansible_processor_vcpus*2 }};error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;events {worker_connections  1024;
}http {include       /etc/nginx/mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;sendfile        on;#tcp_nopush     on;keepalive_timeout  65;#gzip  on;include /etc/nginx/conf.d/*.conf;
}

修改template剧本

[root@zhaoyj ansible]# cat templates.yml 
---
- hosts: testremote_user: roottasks:- name: install pkgyum: name=nginx- name: copy templatetemplate: src=nginx.conf.j2 dest=/etc/nginx/nginx.confnotify: restart service- name: start serviceservice: name=nginx state=started enabled=yeshandlers:- name: restart serviceservice:  name=nginx state=restarted
...

再次执行

[root@zhaoyj ansible]# ansible-playbook templates.yml PLAY [test] ***********************************************************************************************************************************************************************************************************TASK [Gathering Facts] ************************************************************************************************************************************************************************************************
ok: [192.168.6.249]TASK [install pkg] ****************************************************************************************************************************************************************************************************
ok: [192.168.6.249]TASK [copy template] **************************************************************************************************************************************************************************************************
changed: [192.168.6.249]TASK [start service] **************************************************************************************************************************************************************************************************
changed: [192.168.6.249]RUNNING HANDLER [restart service] *************************************************************************************************************************************************************************************
changed: [192.168.6.249]PLAY RECAP ************************************************************************************************************************************************************************************************************
192.168.6.249              : ok=5    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

查看配置文件是否读取变量

192.168.6.249 | CHANGED | rc=0 >>
worker_processes  16;
[root@zhaoyj ansible]# ansible test -m shell -a "ps aux|grep nginx"
192.168.6.249 | CHANGED | rc=0 >>
root     16342  0.0  0.0  49072  1168 ?        Ss   17:16   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx    16343  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16344  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16345  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16346  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16347  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16348  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16349  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16350  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16351  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16352  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16353  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16354  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16355  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16356  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16357  0.0  0.0  49460  1900 ?        S    17:16   0:00 nginx: worker process
nginx    16358  0.0  0.0  49460  1636 ?        S    17:16   0:00 nginx: worker process
root     17699  0.0  0.0 113284  1204 pts/1    S+   17:20   0:00 /bin/sh -c ps aux|grep nginx
root     17701  0.0  0.0 112816   960 pts/1    S+   17:20   0:00 grep nginx

when的使用

条件测试:
如果需要根据变量,facts或此前任务的执行结果来做为某task执行与否的前提是要用到条件测试,通过when语句实现,在task中使用,jinja2的语法格式
when语句:
在task后添加when子句即可使用条件测试,when语句支持jinja2语法
比如:
在这里插入图片描述

查看版本号

[root@zhaoyj ansible]# ansible test -m setup -a "filter="*distribution*""
192.168.6.249 | SUCCESS => {"ansible_facts": {"ansible_distribution": "CentOS", "ansible_distribution_file_parsed": true, "ansible_distribution_file_path": "/etc/redhat-release", "ansible_distribution_file_variety": "RedHat", "ansible_distribution_major_version": "7", "ansible_distribution_release": "Core", "ansible_distribution_version": "7.9", "discovered_interpreter_python": "/usr/bin/python"}, "changed": false
}

记录 “ansible_distribution_major_version”: “7”, 设置当系统等于7时,复制配置文件
修改模板文件

[root@zhaoyj ansible]# cat templates.yml 
---
- hosts: testremote_user: roottasks:- name: install pkgyum: name=nginx- name: copy templatetemplate: src=nginx.conf.j2 dest=/etc/nginx/nginx.confwhen: ansible_distribution_major_version == "7"notify: restart service- name: start serviceservice: name=nginx state=started enabled=yeshandlers:- name: restart serviceservice:  name=nginx state=restarted
...

执行剧本

[root@zhaoyj ansible]# ansible-playbook templates.yml PLAY [test] ***********************************************************************************************************************************************************************************************************TASK [Gathering Facts] ************************************************************************************************************************************************************************************************
ok: [192.168.6.249]TASK [install pkg] ****************************************************************************************************************************************************************************************************
ok: [192.168.6.249]TASK [copy template] **************************************************************************************************************************************************************************************************
changed: [192.168.6.249]TASK [start service] **************************************************************************************************************************************************************************************************
changed: [192.168.6.249]RUNNING HANDLER [restart service] *************************************************************************************************************************************************************************************
changed: [192.168.6.249]PLAY RECAP ************************************************************************************************************************************************************************************************************
192.168.6.249              : ok=5    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   [root@zhaoyj ansible]# ansible test -m shell -a "cat /etc/nginx/nginx.conf|grep centos"
192.168.6.249 | CHANGED | rc=0 >>
#centos 7

嵌套变量传递

我们在制作模板是支持传递变量,可传递单一变量,或者是以列表方式传递,例如:

---
- hosts: testremote_user: roottasks:- name: create some groupsgroup: name={{ item }}with_items:- group1- group2- group3- name: create some useruser: name={{ item.name }} group={{ item.group }}with_items:- { name: 'name1', group: 'group1' }- { name: 'name2', group: 'group2' }- { name: 'name3', group: 'group3' }
...

执行


```bash
[root@192-168-6-228 ansible]# ansible-playbook  test.yml PLAY [test] ****************************************************************************************************************************************************************************TASK [Gathering Facts] *****************************************************************************************************************************************************************
ok: [192.168.6.223]TASK [create some groups] **************************************************************************************************************************************************************
changed: [192.168.6.223] => (item=group1)
changed: [192.168.6.223] => (item=group2)
changed: [192.168.6.223] => (item=group3)TASK [create some user] ****************************************************************************************************************************************************************
changed: [192.168.6.223] => (item={u'group': u'group1', u'name': u'name1'})
changed: [192.168.6.223] => (item={u'group': u'group2', u'name': u'name2'})
changed: [192.168.6.223] => (item={u'group': u'group3', u'name': u'name3'})PLAY RECAP *****************************************************************************************************************************************************************************
192.168.6.223              : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 

验证结果

[root@192-168-6-228 ansible]# ansible test -m shell -a "getent passwd"|grep name
name1:x:1003:1003::/home/name1:/bin/bash
name2:x:1004:1004::/home/name2:/bin/bash
name3:x:1005:1005::/home/name3:/bin/bash[root@192-168-6-228 ansible]# ansible test -m shell -a "getent group|grep 100[3-5]"
192.168.6.223 | CHANGED | rc=0 >>
group1:x:1003:
group2:x:1004:
group3:x:1005:

FOR循环与条件判断

FOR循环

格式**(% for vhost in nginx_vhosts %)**
示例:

[root@192-168-6-228 ansible]# cat test1.yml 
---
- hosts: testremote_user: rootvars: ports:- 81 - 82- 83tasks:- name: copy filetemplate: src=port.j2 dest=/tmp/port 
...

编写一个模板文件

[root@192-168-6-228 ansible]# cat templates/port.j2
{% for port in ports %}
server{listen {{ port }}
}
{% endfor %}

注意:for循环里的in ports,这个ports需要和剧本里定义的一样
执行

[root@192-168-6-228 ansible]# ansible-playbook test1.yml PLAY [test] ****************************************************************************************************************************************************************************TASK [Gathering Facts] *****************************************************************************************************************************************************************
ok: [192.168.6.223]TASK [copy file] ***********************************************************************************************************************************************************************
changed: [192.168.6.223]PLAY RECAP *****************************************************************************************************************************************************************************
192.168.6.223              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

结果查看

[root@192-168-6-228 ansible]# ansible test -m shell -a "cat /tmp/port"
192.168.6.223 | CHANGED | rc=0 >>
server{listen 81
}
server{listen 82
}
server{listen 83
}

也可以改成字典方式去循环,例如:

[root@192-168-6-228 ansible]# cat test1.yml 
---
- hosts: testremote_user: rootvars: ports:- listen_port: 81 - listen_port: 82- listen_port: 83tasks:- name: copy filetemplate: src=port.j2 dest=/tmp/port 
...

模板修改

[root@192-168-6-228 ansible]# cat templates/port.j2
{% for port in ports %}
server{listen {{ port.listen_port }}
}
{% endfor %}

先删除之前的文件在看效果

[root@192-168-6-228 ansible]# ansible test -m shell -a "rm -f  /tmp/port"
[WARNING]: Consider using the file module with state=absent rather than running 'rm'.  If you need to use command because file 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.6.223 | CHANGED | rc=0 >>[root@192-168-6-228 ansible]# ansible test -m shell -a "cat   /tmp/port"
192.168.6.223 | FAILED | rc=1 >>
cat: /tmp/port: No such file or directorynon-zero return code[root@192-168-6-228 ansible]# ansible-playbook test1.yml PLAY [test] ****************************************************************************************************************************************************************************TASK [Gathering Facts] *****************************************************************************************************************************************************************
ok: [192.168.6.223]TASK [copy file] ***********************************************************************************************************************************************************************
changed: [192.168.6.223]PLAY RECAP *****************************************************************************************************************************************************************************
192.168.6.223              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   [root@192-168-6-228 ansible]# ansible test -m shell -a "cat   /tmp/port"
192.168.6.223 | CHANGED | rc=0 >>
server{listen 81
}
server{listen 82
}
server{listen 83
}

与第一种方法是一致的

if判断

模板里也支持if判断。例如修改上面的模板,当listen_port变量为空,就不执行

---
- hosts: testremote_user: rootvars: ports:- listen_port: 81 - listen_port: 82- listen_port:tasks:- name: copy filetemplate: src=port.j2 dest=/tmp/port 
...

模板修改

[root@192-168-6-228 ansible]# cat templates/port.j2
{% for port in ports %}
server{
{% if port.listen_port is none %}listen {{ port.listen_port }}
{% endif %}
}
{% endfor %}

if是none情况下,代表参数定义但是值为空是真
if是defined情况下,代表参数定义了为真
if是undefined情况下,代表参数未定义为真

结果查看

[root@192-168-6-228 ansible]# ansible-playbook  test3.yml PLAY [test] ****************************************************************************************************************************************************************************TASK [Gathering Facts] *****************************************************************************************************************************************************************
ok: [192.168.6.223]TASK [copy file] ***********************************************************************************************************************************************************************
changed: [192.168.6.223]PLAY RECAP *****************************************************************************************************************************************************************************
192.168.6.223              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   [root@192-168-6-228 ansible]# ansible test -m shell -a "cat   /tmp/port"
192.168.6.223 | CHANGED | rc=0 >>
server{listen 
}

相关文章:

Ansible从入门到精通【六】

大家好&#xff0c;我是早九晚十二&#xff0c;目前是做运维相关的工作。写博客是为了积累&#xff0c;希望大家一起进步&#xff01; 我的主页&#xff1a;早九晚十二 专栏名称&#xff1a;Ansible从入门到精通 立志成为ansible大佬 ansible templates 模板&#xff08;templa…...

国企的大数据岗位方向的分析

现如今大数据已无所不在&#xff0c;并且正被越来越广泛的被应用到历史、政治、科学、经济、商业甚至渗透到我们生活的方方面面中&#xff0c;获取的渠道也越来越便利。 今天我们就来聊一聊“大屏应用”&#xff0c;说到大屏就一定要聊到数据可视化&#xff0c;现如今&#xf…...

【MySQL--->数据类型】

文章目录 [TOC](文章目录) 一、数据类型分类二、整型类型三、bit(位)类型四、float类型五、decimal类型六、char和varchar类型1.char类型2.varchar3.char与varchar的区别 七、日期与时间类型八、enum和set 一、数据类型分类 二、整型类型 数值类型有数据存储上限,而且每个类型都…...

Ceph部署

一、存储基础 1&#xff09;单机存储设备 ●DAS&#xff08;直接附加存储&#xff0c;是直接接到计算机的主板总线上去的存储&#xff09; IDE、SATA、SCSI、SAS、USB 接口的磁盘 所谓接口就是一种存储设备驱动下的磁盘设备&#xff0c;提供块级别的存储 ●NAS&#xff08;…...

打工日记-Vue3+Ts二次封装el-table

el-table是elementUI中的表格组件&#xff0c;在后台把管理系统中&#xff0c;也是一个比较常用的组件&#xff0c;目前有一个比较好的开源项目ProTable&#xff0c;这个项目做的很好&#xff0c;集成了搜索&#xff0c;表格&#xff0c;分页器功能很强大。但在我的实际使用中也…...

funbox3靶场渗透笔记

funbox3靶场渗透笔记 靶机地址 https://download.vulnhub.com/funbox/Funbox3.ova 信息收集 fscan找主机ip192.168.177.199 .\fscan64.exe -h 192.168.177.0/24___ _/ _ \ ___ ___ _ __ __ _ ___| | __/ /_\/____/ __|/ __| __/ _ |/ …...

springcloud3 hystrix实现服务降级,熔断,限流以及案例配置

一 hystrix的作用 1.1 降级&#xff0c;熔断&#xff0c;限流 1.服务降级&#xff1a; A方案出现问题&#xff0c;切换到兜底方案B&#xff1b; 2.服务熔断&#xff1a;触发规则&#xff0c;出现断电限闸&#xff0c;服务降级 3.服务限流&#xff1a;限制请求数量。 二 案例…...

ComponentOne Studio ASP.NET MVC Crack

ComponentOne Studio ASP.NET MVC Crack FlexReport增强功能 添加了对在Microsoft Windows上部署Microsoft Azure的支持。 添加了对显示嵌入字体的支持。 .NET标准版的经典C1PDF(Beta版) GrapeCity的经典C1Pdf库现在提供了基于Microsoft.NET标准的版本。在任何.NET应用程序(包括…...

OPENCV C++(十一)

鼠标响应函数 //鼠标响应函数 void on_mouse(int EVENT, int x, int y, int flags, void* userdata) {Mat hh;hh *(Mat*)userdata;switch (EVENT){case EVENT_LBUTTONDOWN:{vP.x x;vP.y y;drawMarker(hh, vP, Scalar(255, 255, 255));//circle(hh, vP, 4, cvScalar(255, 255…...

ES使用心得

客户端 Transport Client已经快要废弃了&#xff0c;官方推荐使用High Level REST Client。 常用命令 启停 systemctl start elasticsearch systemctl stop elasticsearch节点状态 curl http://myservice1:9200/_cat/nodes?vip heap.percent ram.percent cpu l…...

Stable Diffusion - 幻想 (Fantasy) 风格与糖果世界 (Candy Land) 人物提示词配置

欢迎关注我的CSDN&#xff1a;https://spike.blog.csdn.net/ 本文地址&#xff1a;https://spike.blog.csdn.net/article/details/132212193 图像由 DreamShaper8 模型生成&#xff0c;融合糖果世界。 幻想 (Fantasy) 风格图像是一种以想象力为主导的艺术形式&#xff0c;创造了…...

部署K8S集群

目录 一、环境搭建 1、准备环境 2、安装master节点 3、安装k8s-master上的node 4、安装配置k8s-node1节点 5、安装k8s-node2节点 6、为所有node节点配置flannel网络 7、配置docker开启加载防火墙规则允许转发数据 二、k8s常用资源管理 1、创建一个pod 2、pod管理 一、…...

在时间和频率域中准确地测量太阳黑子活动及使用信号处理工具箱(TM)生成广泛的波形,如正弦波、方波等研究(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…...

一百五十四、Kettle——Linux上安装Kettle9.3(踩坑,亲测有效,附截图)

一、目的 由于kettle8.2在Linux上安装后&#xff0c;共享资源库创建遇到一系列问题&#xff0c;所以就换成kettle9.3 二、kettle版本以及安装包网盘链接 kettle9.3.0安装包网盘链接 链接&#xff1a;https://pan.baidu.com/s/1MS8QBhv9ukpqlVQKEMMHQA?pwddqm0 提取码&…...

PackageNotFoundError: No package metadata was found for bitsandbytes解决方案

大家好,我是爱编程的喵喵。双985硕士毕业,现担任全栈工程师一职,热衷于将数据思维应用到工作与生活中。从事机器学习以及相关的前后端开发工作。曾在阿里云、科大讯飞、CCF等比赛获得多次Top名次。现为CSDN博客专家、人工智能领域优质创作者。喜欢通过博客创作的方式对所学的…...

uni-app和springboot完成前端后端对称加密解密流程

概述 使用对称加密的方式实现。前端基于crypto-js。uni-app框架中是在uni.request的基础上&#xff0c;在拦截器中处理的。springboot在Filter中完成解密工作。 uni-app 项目中引入crypto-js。 npm install crypto-js加密方法 const SECRET_KEY CryptoJS.enc.Utf8.parse(…...

【Unity造轮子】制作一个简单的2d抓勾效果(类似蜘蛛侠的技能)

前言 欢迎阅读本文&#xff0c;本文将向您介绍如何使用Unity游戏引擎来实现一个简单而有趣的2D抓勾效果&#xff0c;类似于蜘蛛侠的独特能力。抓勾效果是许多动作游戏和平台游戏中的常见元素&#xff0c;给玩家带来了无限的想象和挑战。 不需要担心&#xff0c;即使您是一…...

Unity 人物连招(三段连击)

一&#xff1a; 连招思路 首先人物角色上有三个攻击实例对象 Damage,每一个damage定义了攻击的伤害值&#xff0c;攻击距离&#xff0c;触发器名称&#xff0c;伤害的发起者&#xff0c;攻击持续时间&#xff0c;攻击重置时间&#xff0c;伤害的碰撞框大小等字段&#xff1a; …...

关于WSL以及docker连接adb的坑

结论 WSL可以连接到adb&#xff0c;需要和主机保持一致的adb型号。主机是windows还是macOS的docker没法直接连接到adb设备&#xff0c;只有主机为Linux才可以。其他平台只能通过TCP网络协议。 具体过程 关于WSL连接adb设备 windows安装adb工具&#xff08;安装可以去官网下…...

python安装第三方包时报错:...\lib\site-packages\pip\_vendor\urllib3\response.py...

安装redis第三方包&#xff1a; pip install redis报错现象&#xff1a; 解决方法&#xff1a;使用以下命令可成功安装 pip install redis -i http://pypi.douban.com/simple --trusted-host pypi.douban.com...

wordpress后台更新后 前端没变化的解决方法

使用siteground主机的wordpress网站&#xff0c;会出现更新了网站内容和修改了php模板文件、js文件、css文件、图片文件后&#xff0c;网站没有变化的情况。 不熟悉siteground主机的新手&#xff0c;遇到这个问题&#xff0c;就很抓狂&#xff0c;明明是哪都没操作错误&#x…...

Cursor实现用excel数据填充word模版的方法

cursor主页&#xff1a;https://www.cursor.com/ 任务目标&#xff1a;把excel格式的数据里的单元格&#xff0c;按照某一个固定模版填充到word中 文章目录 注意事项逐步生成程序1. 确定格式2. 调试程序 注意事项 直接给一个excel文件和最终呈现的word文件的示例&#xff0c;…...

Android15默认授权浮窗权限

我们经常有那种需求&#xff0c;客户需要定制的apk集成在ROM中&#xff0c;并且默认授予其【显示在其他应用的上层】权限&#xff0c;也就是我们常说的浮窗权限&#xff0c;那么我们就可以通过以下方法在wms、ams等系统服务的systemReady()方法中调用即可实现预置应用默认授权浮…...

第 86 场周赛:矩阵中的幻方、钥匙和房间、将数组拆分成斐波那契序列、猜猜这个单词

Q1、[中等] 矩阵中的幻方 1、题目描述 3 x 3 的幻方是一个填充有 从 1 到 9 的不同数字的 3 x 3 矩阵&#xff0c;其中每行&#xff0c;每列以及两条对角线上的各数之和都相等。 给定一个由整数组成的row x col 的 grid&#xff0c;其中有多少个 3 3 的 “幻方” 子矩阵&am…...

USB Over IP专用硬件的5个特点

USB over IP技术通过将USB协议数据封装在标准TCP/IP网络数据包中&#xff0c;从根本上改变了USB连接。这允许客户端通过局域网或广域网远程访问和控制物理连接到服务器的USB设备&#xff08;如专用硬件设备&#xff09;&#xff0c;从而消除了直接物理连接的需要。USB over IP的…...

JS设计模式(4):观察者模式

JS设计模式(4):观察者模式 一、引入 在开发中&#xff0c;我们经常会遇到这样的场景&#xff1a;一个对象的状态变化需要自动通知其他对象&#xff0c;比如&#xff1a; 电商平台中&#xff0c;商品库存变化时需要通知所有订阅该商品的用户&#xff1b;新闻网站中&#xff0…...

基于 TAPD 进行项目管理

起因 自己写了个小工具&#xff0c;仓库用的Github。之前在用markdown进行需求管理&#xff0c;现在随着功能的增加&#xff0c;感觉有点难以管理了&#xff0c;所以用TAPD这个工具进行需求、Bug管理。 操作流程 注册 TAPD&#xff0c;需要提供一个企业名新建一个项目&#…...

SQL慢可能是触发了ring buffer

简介 最近在进行 postgresql 性能排查的时候,发现 PG 在某一个时间并行执行的 SQL 变得特别慢。最后通过监控监观察到并行发起得时间 buffers_alloc 就急速上升,且低水位伴随在整个慢 SQL,一直是 buferIO 的等待事件,此时也没有其他会话的争抢。SQL 虽然不是高效 SQL ,但…...

2025年渗透测试面试题总结-腾讯[实习]科恩实验室-安全工程师(题目+回答)

安全领域各种资源&#xff0c;学习文档&#xff0c;以及工具分享、前沿信息分享、POC、EXP分享。不定期分享各种好玩的项目及好用的工具&#xff0c;欢迎关注。 目录 腾讯[实习]科恩实验室-安全工程师 一、网络与协议 1. TCP三次握手 2. SYN扫描原理 3. HTTPS证书机制 二…...

快刀集(1): 一刀斩断视频片头广告

一刀流&#xff1a;用一个简单脚本&#xff0c;秒杀视频片头广告&#xff0c;还你清爽观影体验。 1. 引子 作为一个爱生活、爱学习、爱收藏高清资源的老码农&#xff0c;平时写代码之余看看电影、补补片&#xff0c;是再正常不过的事。 电影嘛&#xff0c;要沉浸&#xff0c;…...