環境: centos 7
設定系統limit為65535
詳見:
關閉selinux
/etc/sysconfig/selinux配置ssh key配置ansible(ansible目錄ansible_test)selinux=disabled
安裝ansible
yum install epel-release ansible
1、修改ansible配置:vi /etc/ansible/ansible.cfg
# uncomment this to disable ssh key host checking2、設定hosts:vi ansible_test/hostshost_key_checking = false #關閉known hosts提醒
[harbor] -->服務名稱命名3、設定全域性變數 ansible_test/group_vars/all.yml10.199.133.157 -->ip位址
10.199.133.158
[registry]
10.199.133.159
[mysql]
10.199.132.136
open_trigger: "on" -->on缺省會轉化為true需要加上雙引號4、ansible_test/harbor.yml示例配置mysql_host: 10.199.133.158
mysql_user: root
mysql_pwd: 21@aaasafqqqsq
registry_url: 10.199.133.159:5000
harbor_ip: 10.199.133.157
harbor.yml
- hosts: harbor -->對應 hosts中的harbor定義5、ansible task目錄roles:
#- docker -->對應ansible_test/roles/docker,不執行
- master -->對應ansible_test/roles/master
- test_docker_dns -->對應ansible_test/roles/test_docker_dns
ls -l ansible_test/roles/docker/
total 0cat roles/docker/tasks/main.ymldrwxr-xr-x 2 root root 24 jul 13 2016 files -->檔案存放
drwxr-xr-x 2 root root 21 aug 8 15:59 tasks -->ansible執行任務
drwxr-xr-x 2 root root 22 jul 13 2016 templates -->模板
--- ###起始行流程圖- name: copy yum repo file -->拷貝檔案,放置在files目錄中
copy: src=docker.repo dest=/etc/yum.repos.d/docker.repo
- name: copy docker images -->拷貝目錄
copy: src=images/ dest=/tmp/images/
- name: copy container config files -->批量拷貝
copy: src=} dest=}
with_items:
- src: config/jobservice/
- src: config/ui/}/ -->引用全域性變數
- src: config/nginx/
- name: import docker images -->批量執行命令
command: docker load -i }
with_items:
- /tmp/images/golang.tar
- /tmp/images/deploy_log.tar
- /tmp/images/deploy_jobservice.tar
- file: path=/var/log/harbor_jobservice_audit.log state=touch mode="u=rw,g=r,o=r" -->建立檔案
- lineinfile: dest=/etc/resolv.conf line="nameserver 192.168.209.254" -->增加目標主機resolv.conf 的nameserver解析
- lineinfile: dest=/etc/resolv.conf state=absent regexp="10.199.129.21" -->刪除10.199.129.21網域名稱解析
- name: delete restart file -->刪除檔案
file: path=~/restart_docker.sh state=absent
- name: yum makecache -->執行linux命令
command: yum makecache
- name: install docker -->安裝軟體
yum: name=docker state=latest
- name: update docker config file -->使用模板替換檔案
template: src=docker.j2 dest=/etc/sysconfig/docker
- name: enable docker service -->啟動服務
service: name=docker enabled=yes state=started
執行部署harbor
ansible-playbook -i hosts harbor.yml
自動化運維ansible
sever1 172.25.60.1 server2 172.25.60.2 server3 172.25.60.3 etc ansible ansible.cfg 主配置檔案,配置ansible工作特性 etc ansible hosts 主機清單 etc ansible roles 存放角色的目...
ansible自動化批量安裝nginx
ansible安裝及ssh免密登入請參考 ansible playbook 劇本 ansible doc 獲取幫助文件 ansible playbook採用yaml語法 核心元件 hosts 定義單個主機或組,vars定義變數,remote user定義執行命令的遠端使用者,tasks定義執行哪些命...
Ansible自動化部署的運用
ansible,是乙個使用python語言開發的輕量級自動化運維工具。安裝部署過程簡單,學習曲線很平坦。由於業務的關係,需要在集群上部署1000個zabbix agent,借助ansible無疑是最好的選擇了。yum y install ansible 內網情況下,現在ansible及其依賴的rpm...