模塊
yum 安裝 yum模塊python
pip 安裝python相關模塊linux
service 啓動服務nginx
不能都是* 那也會致使每分鐘都執行相同的命令 會撐爆服務器web
groupredis
groupsshell
stateubuntu
namecentos
home服務器
shell架構
uid
password
remove = yes
group 建立組
user 用戶
AD-hoc 這些模塊是這樣稱呼的
yaml
傳參 動態的
yaml
ansible all -m setup ansible_all_ipv4_addresses # ipv4的全部地址 ansible_all_ipv6_addresses # ipv6 的全部地址 ansible_date_time # 獲取到節點控制時間 ansible_default_ipv4 # 默認的ipv4地址 ansible_distribution # 系統 ansible_distribution_major_version # 系統的版本號 ansible_domain # 系統所在的域 ansible_env # 系統的環境變量 ansible_hostname # 系統的主機名 ansible_fqdn # 系統的全名 ansible_machine # 系統的架構 ansible_memory_mb # 系統的內存信息 ansible_os_family # 系統的家族 ansible_pkg_mgr # 系統的包管理工具 ansible_processor_cores # 系統的cpu的核數(每顆) ansible_processor_count # 系統cpu的顆數 ansible_processor_vcpus # 系統cpu的總個數= core * count 核數乘顆數 ansible_python # 系統上的python ansible cache -m setup -a 'filter=*processor*' # 用來搜索filter後面的字段
*匹配數量,表示(0,+%)
? 匹配數量,即是 0 | 1 兩者之一
.除了換行符之外的全部字符
+至少一次(1,+%)
[12365] 匹配內容,存在便可 or 關係
() 分組
{m,}次數,出現m次
{m,}至少m次
{m,n}出現m-n次
a*.b 能夠匹配db
a.*匹配不了db
- hosts: db remote_user: root tasks: - name: createfile copy: content='風蕭蕭兮易水寒' dest=/tmp/a.txt when: a=='3' - name: createfile copy: content='壯士一去兮不復還' dest=/tmp/a.txt when: a=='4'
- hosts: db tasks: - name: wadong tieqiao: wadong - name: tk dong: tk tags: tk
- hosts: web tasks: - name: install_nginx yum: name=nginx - name: copyfile copy: src=/etc/nginx/nignx.conf dest=/etc/nginx/nginx.conf tags: copyfile - name: start service: mame=nginx state=started
ansible-playbook -t copyfile p1.py # 只執行標籤的動做 其他的不執行
一次性建立多個
- hosts: gb tasks: - name: gbqc dong: {{ item }} with_items: - qbqc - cyf - ssfj
- hosts: web task: - name: createuser user: name={{item}} with_items: - max20 - max21 - max22
- host: web tasks: - name: createuser user: name={{ item }} with_items: - eral11 - eral12 - eral13
- hosts: web tasks: - name: crategroup group: name={{ item }} with_items: - max30 - max31 - max32 - name: createuser user: name={{ item.name}} group={{ item.group }} with_items: - {'name':eral11,'group':sex11} - {'name':eral12,'group':sex12} - {'name':eral13,'group':sex13}
jinja2
- hosts: web tasks: - name: installredis yum: name=redis - name: copyfile template: src=/etc/redis.conf dest=/etc/redis.conf - name: start service: name=redis state=started 配置文件:bind {{ansible_default_ipv4.address }}
- hosts: web tasks: - name: installredis yum: name=redis - name: copyfile template: src=redis.conf dest=/etc/redis.conf - name: start service: name=redis state=started
tips: 能夠寫相對路徑,在當下目錄新建一個templates目錄,
而後把文件放在templates目錄中
修改配置文件
- hosts: web tasks: - name: installredis yum: name=redis - name: copyfile template: src=redis.conf dest=/etc/redis.conf tags:copyfile nofity:restart - name:start service: name=redis state=restarted handlers: - name: restart service: name=redis state=restarted
roles 文件夾
文件夾裏面是要建立的每個角色,每個文件夾
每個角色裏面都要有tasks(must),templates,files,handlers,
vars目錄
每一個目錄都要有main.yml文件,經過import_tasks來調用
其中templates文件夾中的文件能夠經過相對路徑來調用
其中files文件夾是否能夠經過相對路徑來調用
hodoop 大數據
setenforce 0 # 用來臨時關閉selinux iptables -F # 臨時關閉防火牆 # 這個須要yum install iptables /etc/seliunx/config # 永久關閉