Centos initialization script:
more /opt/shell/yaml/system_init-busi.yaml
- hosts: "{{ host }}"
tasks:
- name: "disk partition"
parted: device=/dev/{{ item.key }} number=1 state=present
when: not item.value.partitions and ansible_distribution_major_version == "7" and item.key.startswith("vd")
with_dict: "{{ ansible_devices }}"
register: diskPartition
- name: "partition format"
filesystem: dev=/dev/{{ item.item.key }}1 fstype=xfs
when: item.changed != false
with_items: "{{ diskPartition.results }}"
register: partitionFormat
- name: "partition mount"
shell: mkdir /data;UUID=$(blkid {{ item.invocation.module_args.dev }} | cut -d" " -f2);echo "$UUID /data xfs defaults 0 0">> /etc/fstab;mount -a
when: not item.skip_reason is defined
with_items: "{{ partitionFormat.results }}"
- name: rename system
script: "/opt/shell/soft/system/rename.sh {{ hostname }}"
- name: "create user ezrapp"
user:
uid: 200
name: 'ezrapp'
state: 'present'
shell: '/sbin/nologin'
system: yes
- name: "create user ezruser"
user:
name: 'ezruser'
password: "{{ ezrpwd|password_hash('sha512') }}"
state: 'present'
shell: '/bin/bash'
- name: run install_salt.sh
script: /opt/shell/soft/salt/install_salt1.sh
Modify the hostname script:
more /opt/shell/soft/system/rename.sh
#!/bin/bash
. /root/.bash_profile
set -m
if [ ! -n "$1" ] ;then
echo "you have not input a agrs!"
exit
fi
name=$1
version=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
case $version in
6)
sed -i "1s/localhost.localdomain/${name}/" /etc/hosts
sed -i "2c HOSTNAME=${name}" /etc/sysconfig/network
hostname ${name}
service iptables stop
chkconfig iptables off
;;
7)
hostnamectl --static set-hostname $name
systemctl stop firewalld
systemctl disable firewalld
;;
*)
exit
esac
Install the salt script:
more /opt/shell/soft/salt/install_salt1.sh
#!/usr/bin/env bash
#/bin/rm -f /etc/supervisor/conf.d/jaeger.conf
#supervisorctl update
/bin/rm -f /etc/supervisor/conf.d/jaeger.conf
/bin/rm -f /etc/supervisor/conf.d/Venomd_1.0.0.conf
/usr/bin/supervisorctl update
cat << EOF >> /etc/salt/minion
master: 172.21.1.198
id: $(hostname)
EOF
systemctl enable salt-minion && systemctl restart salt-minion
mkdir -p /data/supervisor/
groupadd user
usermod -a -G user ezruser
usermod -a -G user ezrapp
chown -R ezrapp:user /data