zoukankan      html  css  js  c++  java
  • 04Ansible点对点模式

    Ansible点对点模式

    在ansible中快速执行的单条命令,并且不需要保存的命令,可以使用点对点模式。对于复杂的命令则使用 playbook。

    如果不知道该怎么如何使用某个模块,可以使用ansible-doc xxxx查询模块的用法

    shell模块

    帮助:ansible-doc shell

    获取主机名

    [root@ansible-server ~]# ansible test -m shell -a 'hostname' -o
    

    部署apache

    [root@ansible-server ~]# ansible test -m shell -a 'yum -y install httpd' -o
    

    指定执行的并发线程数

    [root@ansible-server ~]# ansible test -m shell -a 'hostname' -o -f 2
    

    -f 2 指定线程数

    Ansible一次命令执行并发的线程数,默认是5

    查询系统负载

    [root@ansible-server ~]# ansible test -m shell -a 'uptime' -o
    

    copy复制模块

    帮助:ansible-doc copy

    [root@ansible-server ~]# ansible test -m copy -a 'src=/etc/hosts dest=/tmp/abc.txt owner=root group=bin mode=777'
    

    使用backup=yes:如果文件已经存在,可以设置进行备份,否则会直接覆盖。

    [root@ansible-server ~]# ansible test -m copy -a 'src=/etc/hosts dest=/tmp/abc.txt owner=root group=bin mode=777 backup=yes'
    

    user用户模块

    帮助:ansible-doc user

    创建用户

    [root@ansible-server ~]# ansible test -m user -a 'name=mike state=present'
    

    删除用户

    [root@ansible-server ~]# ansible test -m user -a 'name=mike state=absent'
    

    修改密码

    # 1.生成加密密码
    [root@ansible-server ~]# echo '777777' | openssl passwd -1 -stdin
    $1$1FSlyMyq$jzU/9Z/bY0WfpLj29ZjO5/
    
    # 2.修改密码
    [root@ansible-server ~]# ansible test -m user -a 'name=mike password="$1$1FSlyMyq$jzU/9Z/bY0WfpLj29ZjO5/"'	
    

    修改shell

    [root@ansible-server ~]# ansible test -m user -a 'name=mike shell=/sbin/noglogin append=yes'
    

    yum软件包模块

    帮助:ansible-doc yum

    升级所有包

    [root@ansible-server ~]# ansible test -m yum -a 'name="*" state=latest'
    

    安装apache

    [root@ansible-server ~]# ansible test -m yum -a 'name="httpd" state=latest'
    

    service服务模块

    帮助:ansible-doc service

    启动服务

    [root@ansible-server ~]# ansible test -m service -a 'name=httpd state=started'
    

    停止服务

    [root@ansible-server ~]# ansible test -m service -a 'name=httpd state=started enabled=yes'
    

    设置开机启动

    [root@ansible-server ~]# ansible test -m service -a 'name=httpd state=stopped'
    

    重启服务

    [root@ansible-server ~]# ansible test -m service -a 'name=httpd state=restarted'
    

    开机禁止启动

    [root@ansible-server ~]# ansible test -m service -a 'name=httpd state=started enabled=no'
    

    file文件模块

    帮助:ansible-doc file

    创建文件

    [root@ansible-server ~]# ansible test -m file -a 'path=/tmp/88.txt mode=777 state=touch'
    

    创建文件夹

    [root@ansible-server ~]# ansible test -m file -a 'path=/tmp/99 mode=777 state=directory'
    

    删除文件

    [root@ansible-server ~]# ansible test -m file -a 'path=/tmp/88.txt state=absent'
    

    setup收集模块

    帮助:ansible-doc setup

    查询所有信息

    [root@ansible-server ~]# ansible test -m setup
    

    查询指定信息

    [root@ansible-server ~]# ansible test -m setup -a 'filter=ansible_processor_cores'
    
  • 相关阅读:
    xml转换为json格式时,如何将指定节点转换成数组 Json.NET
    快速删除C#代码中的空白行
    C#编程中的Image/Bitmap与base64的转换及 Base-64 字符数组或字符串的长度无效问题 解决
    Flash设置(各种版本浏览器包括低版本IE)
    使用vcastr22.swf做flash版网页视频播放器
    使用VLC Activex插件做网页版视频播放器
    web项目 在visual studio 输出窗口显示调试信息
    geos 3.6.3库windows版本 已编译完成的32位版本和64位版本
    vs2017 打开附带的localdb v13
    visual studio code 里调试运行 Python代码
  • 原文地址:https://www.cnblogs.com/ElegantSmile/p/12588804.html
Copyright © 2011-2022 走看看