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

怎么做hello官方网站信息推广平台有哪些

怎么做hello官方网站,信息推广平台有哪些,网站访问量大,用python做的网站模板华子目录 Ansible四个命令模块1.组成2.特点3.区别3.1command、shell模块3.2raw模块 4.command模块4.1参数表4.2free_form参数 5.shell模块5.1作用5.2例如 6.script模块6.1示例 7.raw模块7.1参数7.2示例 文件操作模块1.file模块1.1参数1.2示例 2.copy模块2.1参数 Ansible四个命令…

华子目录

  • Ansible四个命令模块
    • 1.组成
    • 2.特点
    • 3.区别
      • 3.1`command、shell`模块
      • 3.2`raw`模块
    • 4.`command`模块
      • 4.1参数表
      • 4.2`free_form`参数
    • 5.`shell`模块
      • 5.1作用
      • 5.2例如
    • 6.`script`模块
      • 6.1示例
    • 7.`raw`模块
      • 7.1参数
      • 7.2示例
  • 文件操作模块
    • 1.`file`模块
      • 1.1参数
      • 1.2示例
    • 2.copy模块
      • 2.1参数

Ansible四个命令模块

1.组成

  • command、shell、raw

2.特点

  • 应尽量避免使用这三个模块来执行命令,因为其他模块大部分都是幂等性的,可以自动进行更改跟踪。
  • 幂等性输入相同,输出相同,无论多少次执行。比如说确认接口,如果传入订单号,返回确认ok,如果已经确认过了,再次调用确认接口,返回如果还是确认ok,那么这个接口就是满足幂等性
  • command、shell、raw不具备幂等性

3.区别

3.1command、shell模块

  • 相同点:要求受管主机上安装python
  • 不同点:command可以在受管主机上执行Linux命令,但是不支持环境变量和操作符(例如'|' '<' '>' '&'),shell模块需要调用/bin/sh指令执行

3.2raw模块

  • 不需要受管主机安装python,直接使用远程shell运行命令,通常用于无法安装python的系统(例如:网络设备等)

4.command模块

4.1参数表

名称必选备注
chdirno(不是必选参数)运行command命令前先cd到这个目录
createsno如果这个参数对应的文件存在,就不运行command
free_formyes需要执行的脚本(没有真正的参数为free_form)
executableno改变用来执行命令的shell,是可执行文件的绝对路径
removesno如果这个参数对应的文件不存在,就不运行command,与creates参数作用相反
stdinno2.4后的新增,将命令的stdin设置为指定的值

4.2free_form参数

  • 必须参数指定需要远程执行的命令。
  • free_form 参数与其他参数(如果想要使用一个参数,那么则需要为这个参数赋值,也就是name=value模式)并不相同。
  • 如:需要在远程主机上执行 ls 命令时,错误写法:free_form=ls ,因为并没有任何参数的名字是 free_form,若要在远程主机中执行 ls 命令时,直接写成 ls 即可。因为 command 模块的作用是执行命令,所以任何一个可以在远程主机上执行的命令都可以被称为free_form
  • 例:
[root@server ~]# ansible-inventory --graph  #分组查看
@all:|--@ungrouped:|  |--node1.example.com|  |--node2.example.com
[root@server ~]# ansible all -m command -a "ls /root"   #查看目录
node2.example.com | CHANGED | rc=0 >>
公共
模板
视频
图片
文档
下载
音乐
桌面
anaconda-ks.cfg
node1.example.com | CHANGED | rc=0 >>
公共
模板
视频
图片
文档
下载
音乐
桌面
anaconda-ks.cfg
frp_0.56.0_linux_amd64
frp_0.56.0_linux_amd64.tar.gz
mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz
[root@server ~]# ansible all -m command -a "cd /"
node2.example.com | CHANGED | rc=0 >>node1.example.com | CHANGED | rc=0 >>
[root@server ~]# ansible all -m command -a "pwd"
node2.example.com | CHANGED | rc=0 >>
/root
node1.example.com | CHANGED | rc=0 >>
/root
[root@server ~]# ansible all -m command -a "touch file.ansible"
node1.example.com | CHANGED | rc=0 >>node2.example.com | CHANGED | rc=0 >>[root@node1 ~]# ls
公共  文档   模板  下载  anaconda-ks.cfg   file.ansible[root@node2 ~]# ls
公共  模板  视频    anaconda-ks.cfg  file.ansible
[root@server ~]# ansible all -m command -a "ls /root creates=file.ansible"   #当文件file.ansible存在则就不执行前面的命令
node1.example.com | SUCCESS | rc=0 >>
skipped, since file.ansible existsDid not run command since 'file.ansible' exists
node2.example.com | SUCCESS | rc=0 >>
skipped, since file.ansible existsDid not run command since 'file.ansible' exists
[root@server ~]# ansible all -m command -a "ls /root removes=file.ansible"  #当文件file.ansible不存在则就不执行前面的命令
node2.example.com | CHANGED | rc=0 >>
公共
模板
视频
图片
文档
下载
音乐
桌面
anaconda-ks.cfg
file.ansible
node1.example.com | CHANGED | rc=0 >>
公共
模板
视频
图片
文档
下载
音乐
桌面
anaconda-ks.cfg
file.ansible
frp_0.56.0_linux_amd64
frp_0.56.0_linux_amd64.tar.gz
mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz
#无法使用管道符和输入输出重定向
[root@server ~]# ansible all -m command -a "echo 'hello world' > file.ansible"
node1.example.com | CHANGED | rc=0 >>
hello world > file.ansible
node2.example.com | CHANGED | rc=0 >>
hello world > file.ansible
[root@server ~]# ansible all -m command -a "cat file.ansible"
node2.example.com | CHANGED | rc=0 >>node1.example.com | CHANGED | rc=0 >>[root@server ~]# ansible all -m command -a "ls /root | grep file.ansible"
node2.example.com | FAILED | rc=2 >>
file.ansible/root:
公共
模板
视频
图片
文档
下载
音乐
桌面
anaconda-ks.cfg
file.ansiblels: 无法访问 '|': 没有那个文件或目录
ls: 无法访问 'grep': 没有那个文件或目录non-zero return code
node1.example.com | FAILED | rc=2 >>
file.ansible/root:
公共
模板
视频
图片
文档
下载
音乐
桌面
anaconda-ks.cfg
file.ansible
frp_0.56.0_linux_amd64
frp_0.56.0_linux_amd64.tar.gz
mysql-8.0.37-linux-glibc2.17-x86_64.tar.xzls: 无法访问 '|': 没有那个文件或目录
ls: 无法访问 'grep': 没有那个文件或目录non-zero return code

5.shell模块

5.1作用

    • 远程主机shell进程执行命令,从而支持shell的特性如管道等参数command模块几乎相同,但在执行命令的时候调用的是/bin/sh

5.2例如

[root@server ~]# ansible all -m shell -a "tree chdir=/root"
node2.example.com | CHANGED | rc=0 >>
.
├── 公共
├── 模板
├── 视频
├── 图片
├── 文档
├── 下载
├── 音乐
├── 桌面
├── anaconda-ks.cfg
└── file.ansible8 directories, 2 files
node1.example.com | CHANGED | rc=0 >>
.
├── 公共
├── 模板
├── 视频
├── 图片
├── 文档
├── 下载
├── 音乐
├── 桌面
├── anaconda-ks.cfg
├── file.ansible
├── frp_0.56.0_linux_amd64
│   ├── frpc
│   ├── frpc.toml
│   └── LICENSE
├── frp_0.56.0_linux_amd64.tar.gz
└── mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz9 directories, 7 files
[root@server ~]# ansible node1.example.com -m shell -a "echo 'hello world' > file.ansible"
node1.example.com | CHANGED | rc=0 >>[root@server ~]# ansible node1.example.com -m shell -a "cat /root/file.ansible"
node1.example.com | CHANGED | rc=0 >>
hello world

6.script模块

  • scriptshell 类似,都可以执行脚本
  • 区别script执行的脚本在ansible管理机上,而shell执行的脚本必须先放到目标节点上去,才能执行
  • shell执行可以使用环境变量bash等,但是script只是执行.sh脚本,不能带 bash

6.1示例

  • server端写一个t2.sh的脚本
[root@server ~]# vim t2.sh
#!/bin/bash
echo "hello world"[root@server ~]# ansible all -m script -a "t2.sh"
node2.example.com | CHANGED => {"changed": true,"rc": 0,"stderr": "Shared connection to node2.example.com closed.\r\n","stderr_lines": ["Shared connection to node2.example.com closed."],"stdout": "hello world\r\n","stdout_lines": ["hello world"]
}
node1.example.com | CHANGED => {"changed": true,"rc": 0,"stderr": "Shared connection to node1.example.com closed.\r\n","stderr_lines": ["Shared connection to node1.example.com closed."],"stdout": "hello world\r\n","stdout_lines": ["hello world"]
}
  • 在目标节点上
[root@node1 ~]# vim t2.sh
#!/bin/bash
echo "hello world"[root@node2 ~]# vim t2.sh
#!/bin/bash
echo "hello world"[root@server ~]# ansible all -m shell -a "bash t2.sh"
node2.example.com | CHANGED | rc=0 >>
hello world
node1.example.com | CHANGED | rc=0 >>
hello world

7.raw模块

raw模块主要用于执行一些低级的命令,一般适用于下列两种场景

  • 第一种:在较老的(python2.4和之前的版本)主机上执行命令
  • 第二种:对任何没有安装python的设备(如路由器
  • 注意:在任何其他情况下,使用shellcommand模块更为合适

7.1参数

名称必选备注
executableno(可以不选)改变用来执行命令的shell,是可执行文件的绝对路径
free_formyes需要执行的脚本(没有真正的参数为free_form)

7.2示例

[root@server ~]# ansible all -m raw -a "pwd"
node1.example.com | CHANGED | rc=0 >>
/root
Shared connection to node1.example.com closed.node2.example.com | CHANGED | rc=0 >>
/root
Shared connection to node2.example.com closed.
[root@server ~]# ansible all -m raw -a "echo 'hello world'"
node1.example.com | CHANGED | rc=0 >>
hello world
Shared connection to node1.example.com closed.node2.example.com | CHANGED | rc=0 >>
hello world
Shared connection to node2.example.com closed.

文件操作模块

1.file模块

作用:实现对文件的基本操作,如:创建目录或文件,删除目录或文件,修改文件权限

1.1参数

  • path必须参数,用于指定要操作的文件目录,在之前版本的ansible中,使用dest参数或者name参数指定要操作的文件或目录,为了兼容之前的版本,使用destname也可以
  • state:
    • 格式path=“路径” state= touch | directory | link | hard | absent
    • 此参数使用灵活,如:在远程主机中创建一个目录,则使用path参数指定对应的目录路径,假设在远程主机上创建/testdir/a/b目录,则设置路径:path=/testdir/a/b,但ansible无法从/testdir/a/b这个路径看出b是一个文件还是一个目录,所以需要通过state参数进行说明
参数含义
state=absent删除远程机器上的指定文件目录
state=directory创建一个空目录
state=file查看指定目录是否存在
state=touch创建一个空文件
state=hard/link创建链接文件
  • src:当state设置为link或者hard时,表示创建一个软链硬链,则必须通过指明src参数即可指定链接源

  • force : 当state=link的时,使用force=yes 参数表示强制创建链接文件,该文件分为三种情况:

    • 当要创建的链接文件指向的源文件不存在时,使用此参数,可以先强制创建出链接文件
    • 存储目录中已经存在链接文件同名的文件时,会将同名文件覆盖为链接文件相当于删除同名文件创建链接文件
    • 当你要创建链接文件目录中已经存在链接文件同名的文件,并且链接文件指向的源文件也不存在,这时会强制替换同名文件为链接文件
  • owner:用于指定被操作文件的属主信息属主对应的用户必须在远程主机中存在,否则会报错

  • group:用于指定被操作文件的属组属组对应的必须在远程主机中存在,否则会报错

  • mode:用于指定被操作文件权限,如:

    • 要将文件权限设置为: “rw-r-x---”,则可以使用mode=650进行设置,或者使用mode=0650
    • 要设置特殊权限,如:为二进制文件设置suid,则可以使用mode=4700
  • recurse:当要操作的文件目录时,recurse设置为yes可以递归修改目录中文件的属性权限

1.2示例

  • 在所有远程主机上创建一个名为 data的目录,如果存在不做操作
[root@server ~]# ansible all -m file -a "path=/root/data state=directory"
node1.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"gid": 0,"group": "root","mode": "0755","owner": "root","path": "/root/data","size": 6,"state": "directory","uid": 0
}
node2.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"gid": 0,"group": "root","mode": "0755","owner": "root","path": "/root/data","size": 6,"state": "directory","uid": 0
}[root@server ~]# ansible all -m command -a "ls chdir=/root"
node1.example.com | CHANGED | rc=0 >>
公共
模板
视频
图片
文档
下载
音乐
桌面
anaconda-ks.cfg
data
file.ansible
frp_0.56.0_linux_amd64
frp_0.56.0_linux_amd64.tar.gz
mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz
t2.sh
node2.example.com | CHANGED | rc=0 >>
公共
模板
视频
图片
文档
下载
音乐
桌面
anaconda-ks.cfg
data
file.ansible
t2.sh
  • node1主机上创建一个名为testfile1的文件,如果testfile1文件已经存在,则会更新文件的时间戳,与touch命令的作用相同
[root@server ~]# ansible node1.example.com -m file -a "path=/root/data/testfile1 state=touch"
node1.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/data/testfile1","gid": 0,"group": "root","mode": "0644","owner": "root","size": 0,"state": "file","uid": 0
}[root@server ~]# ansible node1.example.com -m command -a "ls chdir=/root/data"
node1.example.com | CHANGED | rc=0 >>
file1
testfile1
  • node1上为testfile1文件创建软链接文件,软链接名为linkfile1
[root@server ~]# ansible node1.example.com -m file -a "path=/root/data/linkfile1 state=link src=/root/data/testfile1"
node1.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/data/linkfile1","gid": 0,"group": "root","mode": "0777","owner": "root","size": 20,"src": "/root/data/testfile1","state": "link","uid": 0
}[root@server ~]# ansible node1.example.com -m command -a "ls chdir=/root/data"
node1.example.com | CHANGED | rc=0 >>
file1
linkfile1
testfile1
  • node1上为 testfile1 文件创建硬链接文件,硬链接名为 hardfile1(类似于复制
[root@server ~]# ansible node1.example.com -m file -a "path=/root/data/hardfile1 state=hard src=/root/data/testfile1"
node1.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/data/hardfile1","gid": 0,"group": "root","mode": "0644","owner": "root","size": 0,"src": "/root/data/testfile1","state": "hard","uid": 0
}[root@server ~]# ansible node1.example.com -m command -a "ls /root/data"
node1.example.com | CHANGED | rc=0 >>
file1
hardfile1
linkfile1
testfile1
  • 在创建链接文件时,如果源文件不存在,或者链接文件与其他文件同名时,强制覆盖同名文件或者创建链接文件,参考上述force参数的解释
[root@server ~]# ansible node1.example.com -m file -a "path=/root/data/linkfile3 state=link src=/root/data/123 force=yes"   #注意:123文件不存在
[WARNING]: Cannot set fs attributes on a non-existent symlink target. follow should be
set to False to avoid this.
node1.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/data/linkfile3","src": "/root/data/123"
}[root@server ~]# ansible node1.example.com -m command -a "ls chdir=/root/data"
node1.example.com | CHANGED | rc=0 >>
file1
hardfile1
linkfile1
linkfile3
testfile1
  • 删除node1上的/root/data目录
[root@server ~]# ansible node1.example.com -m file -a "path=/root/data state=absent"
node1.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"path": "/root/data","state": "absent"
}[root@server ~]# ansible node1.example.com -m command -a "ls chdir=/root"
node1.example.com | CHANGED | rc=0 >>
公共
模板
视频
图片
文档
下载
音乐
桌面
anaconda-ks.cfg
file.ansible
frp_0.56.0_linux_amd64
frp_0.56.0_linux_amd64.tar.gz
mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz
t2.sh
  • 创建文件目录的时候指定属主,或者修改远程主机上的文件或目录的属主
[root@server ~]# ansible all -m file -a "path=/root/testfile1 state=touch owner=redhat"  #新建文件并指定为属主为redhat,组默认为root
node2.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/testfile1","gid": 0,"group": "root","mode": "0644","owner": "redhat","size": 0,"state": "file","uid": 1000
}
node1.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/testfile1","gid": 0,"group": "root","mode": "0644","owner": "redhat","size": 0,"state": "file","uid": 1000
}[root@server ~]# ansible all -m file -a "path=/root/testfile2 state=touch"   #新建文件,默认为root
node2.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/testfile2","gid": 0,"group": "root","mode": "0644","owner": "root","size": 0,"state": "file","uid": 0
}
node1.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/testfile2","gid": 0,"group": "root","mode": "0644","owner": "root","size": 0,"state": "file","uid": 0
}
#修改属主和组
[root@server ~]# ansible all -m file -a "path=/root/testfile2 state=touch owner=redhat group=redhat"
node1.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/testfile2","gid": 1000,"group": "redhat","mode": "0644","owner": "redhat","size": 0,"state": "file","uid": 1000
}
node2.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/testfile2","gid": 1000,"group": "redhat","mode": "0644","owner": "redhat","size": 0,"state": "file","uid": 1000
}
  • 创建文件或目录的时候指定权限,或者修改远程主机上的文件或目录的权限
[root@server ~]# ansible all -m file -a "path=/root/testfile1 state=touch mode=777"
node1.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/testfile1","gid": 0,"group": "root","mode": "0777","owner": "redhat","size": 0,"state": "file","uid": 1000
}
node2.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"dest": "/root/testfile1","gid": 0,"group": "root","mode": "0777","owner": "redhat","size": 0,"state": "file","uid": 1000
}
  • 递归方式将目录中的文件属主属组都设置为redhat
[root@server ~]# ansible all -m file -a "path=/data/test/demo state=directory owner=redhat group=redhat recurse=yes"
node2.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"gid": 1000,"group": "redhat","mode": "0755","owner": "redhat","path": "/data/test/demo","size": 6,"state": "directory","uid": 1000
}
node1.example.com | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"gid": 1000,"group": "redhat","mode": "0755","owner": "redhat","path": "/data/test/demo","size": 6,"state": "directory","uid": 1000
}[root@node1 ~]# ll /data/test
总用量 0
drwxr-xr-x 2 redhat redhat 6  77 22:15 demo[root@node2 ~]# ll /data/test/
总用量 0
drwxr-xr-x 2 redhat redhat 6  77 22:15 demo

2.copy模块

作用:拷贝文件,将ansible主机上的文件拷贝到远程受控主机中

2.1参数

参数默认值含义
src用于指定需要copy的文件或目录
backupno,yes当远程主机的目标路径中已存在同名文件,并且与ansible主机中的文件内容不同时,是否对远程主机的文件进行备份,设为yes时,会先备份远程主机中的文件,然后再拷贝到远程主机
content当不使用src指定拷贝的文件时,可以使用content直接指定文件内容,src与content两个参数必有其一,否则会报错
dest用于指定文件将被拷贝到远程主机的哪个目录中,dest为必须参数
group指定文件拷贝到远程主机后的属组,但是远程主机上必须有对应的组,否则会报错
owner指定文件拷贝到远程主机后的属主,但是远程主机上必须有对应的用户,否则会报
mode错文指定文件拷贝到远程主机后的权限,如果你想将权限设置为"rw-r–r–",则可以使用mode=0644表示,如果你想要在user对应的权限位上添加执行权限,则可以使用mode=u+x表示
forceno,yes当远程主机的目标路径中已经存在同名文件,并且与ansible主机中的文件内容不同时,是否强制覆盖,默认值为yes,表示覆盖,如果设置为no,则不会执行覆盖拷贝操作,远程主机中的文件保持不变
http://www.mnyf.cn/news/33252.html

相关文章:

  • 泰安做网站多少钱新郑网络推广
  • 58同城武汉网站建设营销策略怎么写模板
  • wordpress连接失效3分钟搞定网站seo优化外链建设
  • 网站建设及上线流程重庆网站快速排名优化
  • 做五金国际网站哪个好怎样做搜索引擎推广
  • 怎么做国际网站首页北京百度seo服务
  • 合肥建网站公司站内营销推广途径
  • 德阳网站设计seo诊断工具
  • 南宁小程序开发设计合肥百度快速排名优化
  • 苗木企业网站源码查数据的网站有哪些
  • 网站上滚动海报怎么做谷歌海外广告投放
  • 咸阳做网站电话推广运营公司哪家好
  • 宁波正规品牌网站设计艾滋病多久能查出来
  • 麻阳住房和城乡建设局网站云巅seo
  • 昌邑建设局网站竞价排名的服务模式是
  • 武汉网站seo深圳seo网络推广
  • 搜索引擎网站制作seo关键词查询工具
  • 注册网站需要房产证微信搜一搜seo
  • 网站域名备案时间正规网络教育培训机构
  • wordpress做招聘网站广东疫情防控措施
  • 表格在网站后台是居中可到前台为什么不居中seo怎么搞
  • 网站开发Java与Python一个品牌的策划方案
  • 国外代码开源网站电商运营主要负责什么
  • 网站建设的市场调研分析成人技能培训班有哪些
  • 做的最好的美女视频网站游戏推广代理加盟
  • 做网站app怎么赚钱吗学it什么培训机构好
  • 做网站好做吗百度竞价价格查询
  • 分辨率大于1920的网站怎么做今日冯站长之家
  • 常宁市住房和城乡建设局网站成都网站seo技术
  • 哪些网站可以做招商广告语郑州网络推广团队