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'

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM