---

- hosts: gdy

 become: yes

 become user: root

 become method: sudo

 become flags: -i

 gather_facts: no

 vars:

 - disk_sh_dir: "/home/wangyan/playbook/vm"

 - disk_name: "/dev/vdb"

 - dir_name: "/export"

 - pv_name: “/dev/vdb1"

 - vg_name: "export"

 - lv name: "data"

 - lvm: "/dev/{{vg_name}}/{{lv_name}}"

 - dev type: "xfs"


 tasks:

 - name: create disk partition

   script: /{{ disk_sh_dir }}/disk.sh {{disk_name}}

 - name: create a new primarypv

   parted: device={{ disk_name }} number=1 state=present

 - name: create volume group vg

   lvg: vg={{vg_name}} pvs={{pv_name}}

 - name: create logical volume lv

   lvol: vg={{vg_name}} lv={{lv_name}} size=1008FREE

 - name: format lvm

   filesystem: fstype={{dev_type}} dev={{lvm}}

 - name: create mount directory

   file: path={{dir_name}} state=directory

 - name: mount filesystem

   mount: name={{dir_name}} src={{lvm}} fstype={{dev_type}} state=mounted

 - name: modify etc/fstab

   lineinfile:

     dest: /etc/fstab

     line: '/dev/export/data /export xfs defaults 0 0'

   ignore errors: True


 - name: create directory

   file: path=/{{ dir_name }}/{{ item }} state=directory

   with_items:

   - 'log'

   - 'server'

   - 'package'

   - 'shell'

   - 'package/digger-agent'

   - 'package/sgm-probe'

   - 'package/jdk'


 - name: Unarchive packages

   unarchive:

     src: /home/wangyan/playbook/vm/package/{{item.name }}

     dest: /{{ dir_name }}/package/{{ item.path }}

   with_items:

   - { name: 'digger-agent-4.1.7.tar.gz', path: 'digger-agent' }

   - { name: 'sgm-probe-5.3.1-ex.tar.gz', path: 'sgm-probe' }

   - { name: "jdk-8u202-linux-x64.tar.gz", path: 'jdk' }

 - name: create soft link

   file: path={{ dir_name }}/server/{{item.path }} state=link src={{dir_name }}/package/{{ item.path }}/{{ item.src }}

   with items:

   - { src: 'digger-agent-4.1.7',path:'digger-agent'}

   - { src: 'sgm-probe-5.3.1-ex',path:'sgm-probe'}

   - { src: 'jdk1.8.0 202',path: 'jdk'}

 - name: Install jdk

   blockinfile:

     path: '{{ item }}'

     marker: "#{mark} jdk environment variable {mark}"

     block:

       JAVA HOME="/export/package/jdk/jdk1.80 202"

       JRE HOME="$JAVA HOME ire"

       CLASSPATH="$JAVA HOME Li:$JRE HOME Lib"

       PATH="$JAVAHOME/bin:$JRE HOME/bin:$PATH

       export JAVA HOME JRE HOME CLASS PATH PATH

   with items:

     - '/home/pe/.bash_profile'

     - '/etc/profile'

 - name: make java environment effect

   shell: source '{{ item }}'

   with items:

   - '/home/pe/.bash profile'

   - '/etc/profile'

 - name: Install digger

   shell: sed -i'/ARIES/s/^#//g’ {{dir_name }}/package/digger-agent/digger-agent-4.1.7/bin/env before.sh

 - name: Modify diggerenv

   shell: sed -i -e "s@/export/servers/jdk1.8\$@/export/server/jdk@q" -e "s@\"/export/servers/jdk1.8\"@\"/export/server/jdk\"@g" /export/server/digger-agent/bin/env.sh

 - name: Install digger-aentservice

   copy:

     src: files/digger-agent/digger-agent.service

     dest: /usr/lib/systemd/system/digger-agent.service

 - name: start digger-agent server

   systemd:

     name: digger-agent

     enabled: yes

     state: started

     daemon reload: yes

 - name: Install node exporter files

   copy:

     src: files/node exporter

     dest: /usr/local

     owner: root

     group: root

     backup: yes

     mode: 0755

 - name: Install node exporter.service

   copy:

     src: files/node_exporter/node_exporter.service

     dest: /usrlib/systemd/system/nodeexporterservice

     owner:root

     group: root

     backup: yes

 - name: started node exporter

   service:

     name: node exporter

     enabled : yes

     state : restarted

 - name: Install LogErase

   copy:

     src: files/LogErase/LogErase.sh

     dest: /export/shell/LogErase.sh

 - name: Add LogErase cron

   cron:

     name: LogErase

     minute: "*/10"

     user: root

     job: "/bin/bash /export/shell/LogErase.sh >>/export/shell/LogErase.log"

-name: modify hostname

raw: "echo {{ hostname }} > /etc/hostname"