场景:aws跟aliyun多个区域的服务器需要安装部署ilogtail
通过ansible-playbook去安装部署,由于服务器是内网才能ssh进去,所以分开多个区域去执行playbook
主机清单目录,里面hosts文件,由于不同区域的user_defind_id不同,即ilogtail的机器组不同,所以需要对每个区域的主机组设置单独变量
[disp:children]#设置主机组包含 disp_ap-northeast-2 disp_us-east-1 disp_eu-central-1 disp_aliyun-hk [disp:vars]#设置主机组变量 yun_name=other logcollect_binary=logtail.sh logcollect_binary_dest=/home/ubuntu/logtail.sh collectlog_region=ilogtail的project对应的地域 aliyun_uid=阿里云用户的标识 clean_log_file=clean_ilogtail_log.sh clean_log_dest=/home/ubuntu/clean_ilogtail_log.sh [disp_us-east-1] ip地址 [disp_us-east-1:vars] machine_id=sla-prod-disp-aws-us-east-1 [disp_ap-northeast-2] ip地址 [disp_ap-northeast-2:vars] machine_id=sla-prod-disp-aws-ap-northeast-2 [disp_eu-central-1] ip地址 [disp_eu-central-1:vars] machine_id=sla-prod-disp-aws-eu-central-1 [disp_aliyun-hk] ip地址 [disp_aliyun-hk:vars] machine_id=sla-prod-disp-aliyun-hk yun_name=aliyun
ansible的yaml文件
---
- hosts: disp
remote_user: ubuntu
become: true
become_user: root
vars:
IP: "{{ansible_all_ipv4_addresses}}" #获取服务器的IP地址,ilogtail需要对主机名解析
tasks:
- name: create /etc/hosts #在hosts文件插入主机解析
lineinfile: dest=/etc/hosts line="{{IP[0]}} {{ansible_hostname}}"
- name: copy the binary to {{ logcollect_binary_dest }}
copy:
src: "{{ logcollect_binary }}"
dest: "{{ logcollect_binary_dest }}"
mode: 0755
- name: install the logcollect conf to {{ collectlog_region }}
shell: "{{ logcollect_binary_dest }} install {{ collectlog_region }}"
- name: create aliyun uid
file:
path: "/etc/ilogtail/users/{{ aliyun_uid }}"
state: touch
when: yun_name == "other"
- name: create machine id
shell: "echo {{ machine_id }} >/etc/ilogtail/user_defined_id"
- name: copy the cronfile /home/ubuntu
copy:
src: "{{ clean_log_file }}"
dest: "{{ clean_log_dest }}"
mode: 0755
- name: create clean ilogtail log job.
cron:
name: clean_ilogtail_log key
job: ‘/bin/sh {{ clean_log_dest }} 30‘
minute: "0"
hour: "0"
day: "*"
month: "*"
weekday: "*"
state: present
执行,ansible-playbook -i hos disp.yaml
ansible-playbook对服务器安装阿里云日志服务agent--ilogtail
原文:https://www.cnblogs.com/allmdzz/p/13268472.html