1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| vim service_deploy.yaml
- name: install hosts: all user: root gather_facts: false vars: local_path: /opt/tgzs app_dir: /opt/app
tasks: - name: mkdir file: path={{ app_dir }}/{{ app }} state=directory - name: mkdir file: path={{ local_path }} state=directory
- name: copy config and service copy: src: '{{ item.src }}' dest: '{{ item.dest }}' owner: root group: root mode: 0644 force: true
with_items: - { src: '{{ local_path }}/{{ tgz }}', dest: '{{ local_path }}/{{ tgz }}' } - { src: '{{ local_path }}/{{ app }}.service', dest: '/etc/systemd/system/{{ app }}.service' }
register: result - name: Show debug info debug: var=result verbosity=0
- name: tar gz shell: rm -rf /root/{{ app }}* ; \ tar xf {{ local_path }}/{{ tgz }} -C /root/ ; \ /bin/cp -far /root/{{ app }}*/* {{ app_dir }}/{{ app }}/ \
register: result - name: Show debug info debug: var=result verbosity=0
- name: restart service systemd: name: "{{ item }}" state: restarted daemon_reload: yes enabled: yes with_items: - '{{ app }}' register: result
- name: Show debug info debug: var=result verbosity=0
ansible-playbook -i host_file service_deploy.yaml -e "tgz=node_exporter-1.1.2.linux-amd64.tar.gz" -e "app=node_exporter"
|