ansible httpd

卸載服務
ansible all -m shell -a ‘yum -y remove nginx’

檢查用戶 組 uid gid
ansible all -m shell -a ‘getent passwd nginx’
ansible all -m shell -a ‘getent group nginx’

ansible all -m shell -a ‘getent passwd | grep 123’

刪除用戶
ansible all -m shell -a ‘userdel -r nginx’
ansible all -m user -a ‘name=apache state=absent’

驗證
ansible all -m shell -a ‘ss -ntlpe’ /* 端口 */
ansible all -m shell -a ‘ps aux | grep nginx /* 用戶 進程數 */

編譯安裝
一臺機器編譯好
安裝目錄 打包復制

ansible /* 任意文件夾 */

├── group_vars /* 變量 –> 所有 role */


├── File_role.yml /* 與 roles 平級 */
│ …


└── roles


├── Pro_1
│ │
│ ├── tasks /* 必須有 其他文件夾 可無 */
│ │ ├── main.yml
│ │ … /* File.yml */
│ │
│ ├── handlers
│ │ └── main.yml
│ ├── vars
│ │ └── main.yml
│ ├── templates
│ │ ├── File.j2
│ │ …
│ └── files
│ ├── File
│ …


└── Pro_2
├── …

mkdir -pv Pro_1/{tasks,templates,vars,handlers,files}

vim app_role.yml
– hosts: all
remote_user: root

roles:
– app

– Pro_2 /* 調用多個角色 */

– { role: httpd , tags: [‘web’,’httpd’] } /* 添加標簽 */
– { role: nginx , tags: [‘web’,’nginx’] , when: ansible_distribution_major_version == “7” } /* 條件判斷 */
ansible-playbook -C -t httpd app_role.yml /* 挑選 標簽 執行 */

vim tasks/main.yml
– include: group.yml
– include: user.yml
– include: yum.yml
– include: templ.yml
– include: start.yml
– include: copyfile.yml

– include: roles/Pro_2/tasks/File.yml /* 調用其他角色中任務 copy路徑問題…*/
vim group.yml
– name: create group
group: name=app system=yes gid=123
vim user.yml
– name: create user
user: name=app group=app system=yes shell=/sbin/nologin uid=123
vim yum.yml
– name: install package
yum: name=httpd
vim templ.yml
– name: copy conf
template: src=httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf /* File.j2 即可 */
notify: restart service
vim start.yml
– name: start service
service: name=httpd state=started enabled=yes
vim copyfile.yml
– name: copy config
copy: src=vhosts.conf dest=/etc/httpd/conf.d/ owner=app /* 若被其他role調用 注意改 絕對路徑 */

vim handlers/main.yml
– name: restart service
service: name=httpd state=restarted

vim vars/main.yml
username: app
groupname: app

cp /etc/httpd/conf/httpd.conf templates/httpd.conf.j2
vim templates/httpd.conf.j2
Listen {{ ansible_processor_vcpus*10 }}
User {{ username }}
Group {{ groupname }}

 

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/103710

(0)
倪瀟灑倪瀟灑
上一篇 2018-07-23
下一篇 2018-07-23

相關推薦

  • 轉義字符Escape character在正則中的用法

    通過()的在基本正則和擴展正則中的不同使用,詳細介紹了轉義字符的使用注意事項

    Linux筆記 2018-04-13
  • Linux第六天筆記(markdown格式)

    文本處理三劍客 grep:grep,egrep,fgrep pattern:模式,類型 sed awk 通用技術:正則表達式 blank和space的區別: `[:blank:]’ Blank characters: space and tab. ? [:space:]’ ? ? ? Space characters: in theC’ locale, th…

    Linux筆記 2018-04-08
  • systemd與awk的用法

    awk,systemd

    Linux筆記 2018-08-07
  • 新開始,新航程

    ? ? ? ?每一個夏天都是變動的季節,這個夏季我畢業了。大學最后的時光是在實驗室度過的,每天都被瓶瓶罐罐所包圍,鼻子里不時的飄進乙酸乙酯的香味,研究完了生物柴油的催化,是時候該為自己的未來找一條出路了。 ? ? ? ? 大二的時候出于對計算機的著迷,一不小心點進了51cto,從此就走上了不歸路。從計算機網絡到linux,再到mysql,我在這個世界里樂此不…

    Linux筆記 2018-07-21
  • DNS服務、BIND

    DNS:domain name service,協議(C/S,udp53,tcp53) BIND:bekerley internat name domain 注意:named程序的啟動用戶是named用戶,非root用戶,因此需要注意權限和屬主。 本地名稱解析配置文件:hosts linux:/etc/hosts windows:%WINDOWS%/syst…

    2018-03-26
欧美性久久久久