天天看點

ansible常用子產品(command、copy、file、yum、service、firewalld)

本篇部落格的内容在上一篇部落格ansible搭建的基礎上完成:自動化運維工具Ansible的搭建

一、Ansible的command預設子產品的簡單使用

1、在ansible1上執行

test指ansible中test組,-m後指定子產品 -a後加這個子產品的參數

ansible常用子產品(command、copy、file、yum、service、firewalld)

注意:command子產品為預設的子產品,如果不-m指定的話,預設使用的command子產品

二、copy子產品

1、copy

ansible常用子產品(command、copy、file、yum、service、firewalld)

檢視

ansible常用子產品(command、copy、file、yum、service、firewalld)

三、file子產品

檢視docker2某檔案的權限

ansible常用子產品(command、copy、file、yum、service、firewalld)

更改權限:

ansible常用子產品(command、copy、file、yum、service、firewalld)

四、yum子產品

檢視yum子產品的使用方法:

[[email protected] ansible]$ ansible-doc yum
           
ansible常用子產品(command、copy、file、yum、service、firewalld)
ansible常用子產品(command、copy、file、yum、service、firewalld)

注意:我們現在使用的是普通使用者,沒有執行yum指令的權力:

先配置devops使用者的sudo權限:

[[email protected] ~]# vim /etc/sudoers
====================================
 93 devops  ALL=(ALL)       NOPASSWD: ALL
+++++++++++++++++++++++++++++++++++++++++
[[email protected] ~]# vim /etc/sudoers
====================================
 93 devops  ALL=(ALL)       NOPASSWD: ALL
           
  • ansible2
    ansible常用子產品(command、copy、file、yum、service、firewalld)
  • ansible3
    ansible常用子產品(command、copy、file、yum、service、firewalld)
    在docker2-3上,下載下傳httpd服務
#一定要加入-b選項,否則會報錯
[[email protected] ansible]$ ansible test -m yum -a 'name=httpd state=present' -b
           
ansible常用子產品(command、copy、file、yum、service、firewalld)
ansible常用子產品(command、copy、file、yum、service、firewalld)

檢視是否下載下傳成功:

ansible常用子產品(command、copy、file、yum、service、firewalld)

不加-b可以在ansible的配置檔案裡面配置:

[[email protected] ansible]$ vim ansible.cfg
==========================================
[defaults]


inventory      = inventory

[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False
           
  • test組
ansible常用子產品(command、copy、file、yum、service、firewalld)
  • webservers組
ansible常用子產品(command、copy、file、yum、service、firewalld)
ansible常用子產品(command、copy、file、yum、service、firewalld)

解除安裝:

ansible常用子產品(command、copy、file、yum、service、firewalld)

五、service子產品

啟動db組的httpd服務:

ansible常用子產品(command、copy、file、yum、service、firewalld)

測試:

[[email protected] ansible]$ curl 172.25.70.3
           
ansible常用子產品(command、copy、file、yum、service、firewalld)
ansible常用子產品(command、copy、file、yum、service、firewalld)

這是ansible3的httpd服務的預設釋出頁,不太直覺,我們寫一個釋出頁:

ansible常用子產品(command、copy、file、yum、service、firewalld)
ansible常用子產品(command、copy、file、yum、service、firewalld)

六、firewalld子產品

如何在開啟防火牆的情況下,正常使用httpd服務呢?

首先開啟防火牆

ansible常用子產品(command、copy、file、yum、service、firewalld)

測試:

[[email protected] ansible]$ curl ansible3
           
ansible常用子產品(command、copy、file、yum、service、firewalld)

把httpd服務加入防火牆白名單:

ansible常用子產品(command、copy、file、yum、service、firewalld)