1. 程式人生 > 遊戲攻略 >《怪物獵人物語2破滅之翼》羈絆石等級9徽章獲取攻略

《怪物獵人物語2破滅之翼》羈絆石等級9徽章獲取攻略

常用模組幫助文件參考:

https://docs.ansible.com/ansible/2.9/modules/modules_by_category.html

Command 模組

功能:在遠端主機執行命令,此為預設模組,可忽略-m選項

注意:此命令不支援 $VARNAME < > | ; & 等,用shell模組實現

command模組使用詳解:

chdir: 	 	執行命令前,切換到目錄
creates:	當該檔案存在時,不執行該步驟
executable:	切換shell來執行命令,需要使用命令的絕對路徑
free_from:	需要執行的指令碼,一般使用Ansible的-a引數代替。
removes:	當該檔案不存在時,不執行該步驟
warn:		如果在ansible.cfg中存在告警,如果設定了false,不會告警該行

範例:

[root@ansible ~]# ansible all -m command -a 'chdir=/etc cat redhat-release'
192.168.18.222 | CHANGED | rc=0 >>
CentOS Linux release 7.4.1708 (Core) 
192.168.18.132 | CHANGED | rc=0 >>
CentOS Linux release 8.4.2105
192.168.18.130 | CHANGED | rc=0 >>
CentOS Linux release 8.4.2105

[root@ansible ~]#  ansible all -m command -a 'hostname'
192.168.18.222 | CHANGED | rc=0 >>
Quhz.localdomain
192.168.18.132 | CHANGED | rc=0 >>
slave2
192.168.18.130 | CHANGED | rc=0 >>
slave1
Shell模組

功能: 在遠端主機上執行命令,和command相似,用shell執行命令
尤其是用到管道變數等功能的複雜命令
# ansible all -m shell -a 'echo 123456 | passwd --stdin test'

範例:

[root@ansible ~]#ansible all -m shell -a 'echo 123456 | passwd --stdin test'

範例:將shell模組代替command,設為模組

[root@ansible ~]#vim /etc/ansible/ansible.cfg
#修改下面一行
module_name = shell
Script模組

功能:在遠端主機上執行ansible伺服器上的指令碼

範例:

ansible all  -m script -a /data/test.sh
Copy模組

功能:從ansible伺服器主控端複製檔案到遠端主機

#如目標存在,預設覆蓋,此處指定先備份
[root@ansible ~]# ansible all -m copy -a 'src=/root/anaconda-ks.cfg dest=/tmp/anaconda-ks.cfg owner=quhz mode=600 backup=yes'
#指定內容,直接生成目標檔案    
[root@ansible ~]# ansible all -m copy -a "content='this is test file ' dest=/tmp/test.txt"
Fetch模組

功能:從遠端主機提取檔案至ansible的主控端,copy相反,目前不支援目錄

範例:

[root@ansible ~]# ansible all -m fetch -a 'src=/etc/hostname dest=/root/test/'
[root@ansible ~]# tree test/
test/
├── 192.168.18.130
│   └── etc
│       └── hostname
├── 192.168.18.132
│   └── etc
│       └── hostname
└── 192.168.18.222
    └── etc
        └── hostname

6 directories, 3 files
File模組

功能:

主要用於遠端主機上的檔案操作,file模組包含如下選項:

force:需要在兩種情況下強制建立軟連結,一種是原始檔不存在但之後會建立的情況下;另一種是目標軟連結已存在,需要先取消之前的軟鏈,然後建立新的軟鏈,有兩個選項:yes|no

group:定義檔案/目錄的屬組

mode:定義檔案/目錄的許可權

owner:定義檔案/目錄的屬主

path:必選項,定義檔案/目錄的路徑

recurse:遞迴的設定檔案的屬性,只對目錄有效

src:要被連結的原始檔的路徑,只應用於state=link的情況

dest:被連結到的路徑,只應用於state=link的情況

state: directory:如果目錄不存在,建立目錄

file:即使檔案不存在,也不會被建立

link:建立軟連結

hard:建立硬連結

touch:如果檔案不存在,則會建立一個新的檔案,如果檔案或目錄已存在,則更新其最後修改時間

absent:刪除目錄、檔案或者取消連結檔案

範例:

#建立空檔案
[root@ansible ~]# ansible all -m file -a 'path=/tmp/test1.txt state=touch'
#刪除檔案
[root@ansible ~]# ansible all -m file -a 'path=/tmp/test1.txt state=absent'
#設定許可權
[root@ansible ~]# ansible all -m file -a 'path=/tmp/test.txt owner=bin mode=600'
#建立目錄
[root@ansible ~]# ansible all -m file -a 'path=/root/test state=directory'
#建立軟連結
[root@ansible ~]# ansible all -m file -a 'src=/tmp/test.txt dest=/root/test-link state=link'
unarchive模組

功能:解包解壓縮

實現有兩種用法:
1、將ansible主機上的壓縮包傳到遠端主機後解壓縮至特定目錄,設定copy=yes
2、將遠端主機上的某個壓縮包解壓縮到指定路徑下,設定copy=no

常見引數:

  • copy:預設為yes,當copy=yes,拷貝的檔案是從ansible主機複製到遠端主機上,如果設定為copy=no,會在遠端主機上尋找src原始檔
  • remote_src:和copy功能一樣且互斥,yes表示在遠端主機,不在ansible主機,no表示檔案在ansible主機上
  • src:源路徑,可以是ansible主機上的路徑,也可以是遠端主機上的路徑,如果是遠端主機上的路徑,則需要設定copy=no
  • dest:遠端主機上的目標路徑
  • mode:設定解壓縮後的檔案許可權

範例:

ansible all -m unarchive -a 'src=/data/foo.tgz dest=/var/lib/foo'
ansible all -m unarchive -a 'src=/tmp/foo.zip dest=/data copy=no mode=0777'
ansible all -m unarchive -a 'src=https://example.com/example.zip dest=/data copy=no'
Archive模組

功能:打包壓縮

範例:

ansible websrvs -m archive  -a 'path=/var/log/ dest=/data/log.tar.bz2 format=bz2  owner=wang mode=0600'
3.4.9 Hostname模組

功能:管理主機名

範例:

ansible 192.168.18.130 -m hostname -a 'name=node1'
Cron模組

功能:計劃任務
支援時間:minute,hour,day,month,weekday

範例:

#備份資料庫指令碼
[root@centos8 ~]#cat mysql_backup.sh 
mysqldump -A -F --single-transaction --master-data=2 -q -uroot |gzip > /data/mysql_date +%F_%T.sql.gz
#建立任務
ansible 10.0.0.8 -m cron -a 'hour=2 minute=30 weekday=1-5 name="backup mysql" job=/root/mysql_backup.sh'
ansible websrvs   -m cron -a "minute=*/5 job='/usr/sbin/ntpdate 172.20.0.1 &>/dev/null' name=Synctime"
#禁用計劃任務
ansible websrvs   -m cron -a "minute=*/5 job='/usr/sbin/ntpdate 172.20.0.1 &>/dev/null' name=Synctime disabled=yes"
#啟用計劃任務
ansible websrvs   -m cron -a "minute=*/5 job='/usr/sbin/ntpdate 172.20.0.1 &>/dev/null' name=Synctime disabled=no"
#刪除任務
ansible websrvs -m cron -a "name='backup mysql' state=absent"
ansible websrvs -m cron -a 'state=absent name=Synctime'
Yum模組

功能:管理軟體包,只支援RHEL,CentOS,fedora,不支援Ubuntu其它版本

範例:

ansible websrvs -m yum -a ‘name=httpd state=present’  #安裝
ansible websrvs -m yum -a ‘name=httpd state=absent’  #刪除
Service模組

功能:管理服務

範例:

ansible all -m service -a 'name=httpd state=started enabled=yes'
ansible all -m service -a 'name=httpd state=stopped'
ansible all -m service -a 'name=httpd state=reloaded’
ansible all -m shell -a "sed -i 's/^Listen 80/Listen 8080/' /etc/httpd/conf/httpd.conf"
ansible all -m service -a 'name=httpd state=restarted' 
User模組

功能:管理使用者

範例:

#建立使用者
ansible all -m user -a 'name=user1 comment=“test user” uid=2048 home=/app/user1 group=root'

ansible all -m user -a 'name=nginx comment=nginx uid=88 group=nginx groups="root,daemon" shell=/sbin/nologin system=yes create_home=no  home=/data/nginx non_unique=yes'

#刪除使用者及家目錄等資料
ansible all -m user -a 'name=nginx state=absent remove=yes'
Group模組

功能:管理組

範例:

#建立組
ansible websrvs -m group  -a 'name=nginx gid=88 system=yes'
#刪除組
ansible websrvs -m group  -a 'name=nginx state=absent'
Lineinfile模組

ansible在使用sed進行替換時,經常會遇到需要轉義的問題,而且ansible在遇到特殊符號進行替換時,存在問題,無法正常進行替換 。其實在ansible自身提供了兩個模組:lineinfile模組和replace模組,可以方便的進行替換

功能:相當於sed,可以修改檔案內容

範例:

ansible all -m   lineinfile -a "path=/etc/selinux/config regexp='^SELINUX=' line='SELINUX=enforcing'"
ansible all -m lineinfile  -a 'dest=/etc/fstab state=absent regexp="^#"'
Replace模組

該模組有點類似於sed命令,主要也是基於正則進行匹配和替換

範例:

ansible all -m replace -a "path=/etc/fstab regexp='^(UUID.*)' replace='#\1'"  
ansible all -m replace -a "path=/etc/fstab regexp='^#(.*)' replace='\1'"
Setup模組

功能: setup 模組來收集主機的系統資訊,這些 facts 資訊可以直接以變數的形式使用,但是如果主機較多,會影響執行速度,可以使用gather_facts: no來禁止 Ansible 收集 facts 資訊

範例:

ansible all -m setup
ansible all -m setup -a "filter=ansible_nodename"
ansible all -m setup -a "filter=ansible_hostname"
ansible all -m setup -a "filter=ansible_domain"
ansible all -m setup -a "filter=ansible_memtotal_mb"
ansible all -m setup -a "filter=ansible_memory_mb"
ansible all -m setup -a "filter=ansible_memfree_mb"
ansible all -m setup -a "filter=ansible_os_family"
ansible all -m setup -a "filter=ansible_distribution_major_version"
ansible all -m setup -a "filter=ansible_distribution_version"
ansible all -m setup -a "filter=ansible_processor_vcpus"
ansible all -m setup -a "filter=ansible_all_ipv4_addresses"
ansible all -m setup -a "filter=ansible_architecture"
ansible all -m  setup  -a "filter=ansible_processor*"

範例:

[root@ansible ~]# ansible all  -m  setup -a 'filter=ansible_python_version'
192.168.18.222 | SUCCESS => {
    "ansible_facts": {
        "ansible_python_version": "3.7.0",
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false
}
192.168.18.130 | SUCCESS => {
    "ansible_facts": {
        "ansible_python_version": "3.6.8",
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false
}
192.168.18.132 | SUCCESS => {
    "ansible_facts": {
        "ansible_python_version": "3.6.8",
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false
}