zoukankan      html  css  js  c++  java
  • Ansible命令模块(get_url 模块 service模块 systemd模块 )

    1. get_url 模块

    1)帮助语法

    [root@m01 ~]# ansible-doc get_url
    EXAMPLES:
    - name: Download foo.conf
      get_url:
        url: http://example.com/path/file.conf
        dest: /etc/foo.conf
        mode: '0440'
        checksum: 
            sha256:http://example.com/path/sha256sum.txt
            
    url:                 #下载文件的地址
    dest:                 #下载保存的路径
    mode:                #下载之后的权限
    checksum:             #下载时进行验证
        sha256:http://example.com/path/sha256sum.txt
        md5

    2)模块实例

    #下载包
    [root@m01 ~]# ansible 'web_group' -m get_url -a 'url=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm dest=/tmp/'
    
    #下载包并授权
    [root@m01 ~]# ansible 'web_group' -m get_url -a 'url=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm dest=/tmp/ mode=777'
    
    #下载包时验证
    [root@linux /code]# md5sum index.html 
    ba1f2511fc30423bdbb183fe33f3dd0f  index.html
    
    [root@m01 ~]# ansible 'web03' -m get_url -a 'url=http://10.0.0.7/index.html dest=/tmp mode=777 checksum=md5:ba1f2511fc30423bdbb183fe33f3dd0f'

    2.service模块

    1)帮助语法

    [root@m01 ~]# ansible-doc service
    EXAMPLES:
    - name: Start service httpd, if not started
      service:
        name: httpd
        state: started
        enabled: yes
        
    name: httpd            #服务的名字
    state:
        started            #启动服务
        stopped            #停止服务
        restarted        #重启服务
        reloaded        #重载服务
    enabled:            #开机自启
        yes
        no

    2)service实例

    #1.停止nginx服务
    [root@m01 ~]# ansible web03 -m service -a 'name=nginx state=stopped'
    
    #2.启动httpd服务,并加入开机自启
    [root@m01 ~]# ansible web03 -m service -a 'name=httpd state=started enabled=yes'

    3.systemd模块

    1)帮助语法

    [root@m01 ~]# ansible-doc systemd
    EXAMPLES:
    - name: Start service httpd, if not started
      systemd:
        name: httpd
        state: started
        enabled: yes
        daemon_reload: yes
        
    name: httpd            #服务的名字
    state:
        started            #启动服务
        stopped            #停止服务
        restarted        #重启服务
        reloaded        #重载服务
    enabled:            #开机自启
        yes
        no
    daemon_reload:        #后台启动

    2)systemd实例

    #1.停止nginx服务
    [root@m01 ~]# ansible web03 -m systemd -a 'name=nginx state=stopped'
    
    #2.启动httpd服务,并加入开机自启
    [root@m01 ~]# ansible web03 -m systemd -a 'name=httpd state=started enabled=yes'
  • 相关阅读:
    Java并发包concurrent——ConcurrentHashMap
    Eclipse中给SVN添加项目
    Maven在导入其他项目时报错:Plugin execution not covered by lifecycle configuration
    新导入的项目目录结构不对(main目录)
    java.lang.reflect.Method.getAnnotation()方法示例
    彻底理解ThreadLocal
    Oracle查询前几条数据的方法
    PLSQL Developer新手使用教程(图文教程)
    PLSQL连接本地oracle或远程oracle数据库,实现随意切换
    Mysql的Root密码忘记,查看或修改的解决方法(图文介绍)
  • 原文地址:https://www.cnblogs.com/chenlifan/p/13777224.html
Copyright © 2011-2022 走看看