make cobbler support multi target systems
Change-Id: Ibf540efdef10309a7772e99274346f8233ca5e91
This commit is contained in:
parent
1b09286a9b
commit
eefaa34a4f
@ -1,12 +1,12 @@
|
||||
mkdir -p /etc/chef
|
||||
|
||||
## Generate chef rsyslog conf
|
||||
$SNIPPET('kickstart_chef_rsyslog.conf')
|
||||
mkdir -p /var/log/chef
|
||||
|
||||
## Generate validation.pem
|
||||
$SNIPPET('kickstart_chef-validator.pem')
|
||||
## Generate admin.pem
|
||||
$SNIPPET('kickstart_chef-admin.pem')
|
||||
## Generate client.rb
|
||||
$SNIPPET('kickstart_client.rb')
|
||||
$SNIPPET('kickstart_chef_firstrun.sh')
|
||||
$SNIPPET('kickstart_chef_rerun.sh')
|
||||
$SNIPPET('kickstart_knife.rb')
|
||||
$SNIPPET('kickstart_chef_run.sh')
|
||||
$SNIPPET('kickstart_chef_init')
|
||||
|
8
cobbler/snippets/kickstart_chef-admin.pem
Normal file
8
cobbler/snippets/kickstart_chef-admin.pem
Normal file
@ -0,0 +1,8 @@
|
||||
#if $getVar('chef_admin_file', '') == ""
|
||||
#set chef_admin_file = '/etc/chef-server/admin.pem'
|
||||
#end if
|
||||
#set f = $open($chef_admin_file)
|
||||
cat << EOL > /etc/chef/admin.pem
|
||||
#echo $f.read()
|
||||
EOL
|
||||
#silent $f.close()
|
@ -1,25 +0,0 @@
|
||||
cat << EOF > /etc/chef/firstrun.sh
|
||||
#raw
|
||||
#!/bin/bash
|
||||
touch /tmp/chef.log
|
||||
while true; do
|
||||
echo "firstrun chef-client on \`date\`" &>> /tmp/chef.log
|
||||
clients=\$(pgrep chef-client)
|
||||
if [ "\$?" == "0" ]; then
|
||||
echo "there are chef-clients '\$clients' running" &>> /tmp/chef.log
|
||||
sleep 1m
|
||||
else
|
||||
chef-client -L /var/log/chef-client.log &>> /tmp/chef.log
|
||||
if [ "\$?" != "0" ]; then
|
||||
echo "chef-client run failed" &>> /tmp/chef.log
|
||||
sleep 1m
|
||||
else
|
||||
echo "chef-client run success" &>> /tmp/chef.log
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
#end raw
|
||||
EOF
|
||||
chmod +x /etc/chef/firstrun.sh
|
||||
|
@ -15,12 +15,10 @@ ntpdate $ntp_server 2>&1 >> /tmp/ntp.log
|
||||
service ntpd start 2>&1 >> /tmp/ntp.log
|
||||
echo "new date is: `date`" 2>&1 >> /tmp/ntp.log
|
||||
|
||||
rm -rf /var/lib/rsyslog/firstboot_log
|
||||
service rsyslog restart
|
||||
/etc/chef/firstrun.sh
|
||||
/etc/chef/run.sh
|
||||
|
||||
crontab -l > /tmp/mycron
|
||||
echo "*/30 * * * * /etc/chef/rerun.sh" >> /tmp/mycron
|
||||
echo "*/30 * * * * /etc/chef/run.sh" >> /tmp/mycron
|
||||
crontab /tmp/mycron
|
||||
rm /tmp/mycron
|
||||
chkconfig chef off
|
||||
|
@ -1,19 +0,0 @@
|
||||
cat << EOF > /etc/chef/rerun.sh
|
||||
#raw
|
||||
#!/bin/bash
|
||||
echo "rerun chef-client on \`date\`" &>> /tmp/chef.log
|
||||
clients=\$(pgrep chef-client)
|
||||
if [ "\$?" == "0" ]; then
|
||||
echo "there are chef-clients '\$clients' running" &>> /tmp/chef.log
|
||||
exit 1
|
||||
fi
|
||||
chef-client &>> /tmp/chef.log
|
||||
if [ "\$?" != "0" ]; then
|
||||
echo "chef-client run failed" &>> /tmp/chef.log
|
||||
else
|
||||
echo "chef-client run success" &>> /tmp/chef.log
|
||||
fi
|
||||
#end raw
|
||||
EOF
|
||||
chmod +x /etc/chef/rerun.sh
|
||||
|
@ -1,12 +0,0 @@
|
||||
cat << EOL > /etc/rsyslog.d/chef.conf
|
||||
\\$ModLoad imfile
|
||||
\\$InputFileName /var/log/chef-client.log
|
||||
\\$InputFileReadMode 0
|
||||
\\$InputFileTag
|
||||
\\$InputFileStateFile firstboot_log
|
||||
\\$InputFileSeverity notice
|
||||
\\$InputFileFacility local3
|
||||
\\$InputRunFileMonitor
|
||||
\\$InputFilePollInterval 1
|
||||
local3.info @$server:514
|
||||
EOL
|
57
cobbler/snippets/kickstart_chef_run.sh
Normal file
57
cobbler/snippets/kickstart_chef_run.sh
Normal file
@ -0,0 +1,57 @@
|
||||
cat << EOF > /etc/chef/run.sh
|
||||
#!/bin/bash
|
||||
touch /tmp/chef.log
|
||||
while true; do
|
||||
echo "run chef-client on \`date\`" &>> /tmp/chef.log
|
||||
clients=\\$(pgrep chef-client)
|
||||
if [ "\\$?" == "0" ]; then
|
||||
echo "there are chef-clients '\\$clients' running" &>> /tmp/chef.log
|
||||
break
|
||||
else
|
||||
set >> /tmp/chef.log
|
||||
echo "knife search nodes" &>> /tmp/chef.log
|
||||
USER=root HOME=/root knife search node "name:\\$HOSTNAME.*" -i -a name &>> /tmp/chef.log
|
||||
nodes=\\$(USER=root HOME=/root knife search node "name:\\$HOSTNAME.*" -i -a name | grep 'name: ' | awk '{print \\$2}')
|
||||
echo "found nodes \\$nodes" &>> /tmp/chef.log
|
||||
let all_nodes_success=1
|
||||
for node in \\$nodes; do
|
||||
mkdir -p /var/log/chef/\\$node
|
||||
if [ ! -f "/etc/chef/\\$node.pem" ]; then
|
||||
cat << EOL > /etc/rsyslog.d/\\$node.conf
|
||||
\\\\$ModLoad imfile
|
||||
\\\\$InputFileName /var/log/chef/\\$node/chef-client.log
|
||||
\\\\$InputFileReadMode 0
|
||||
\\\\$InputFileTag \\$node
|
||||
\\\\$InputFileStateFile chef_\\${node}_log
|
||||
\\\\$InputFileSeverity notice
|
||||
\\\\$InputFileFacility local3
|
||||
\\\\$InputRunFileMonitor
|
||||
\\\\$InputFilePollInterval 1
|
||||
local3.info @$server:514
|
||||
EOL
|
||||
rm -rf /var/lib/rsyslog/chef_\\$node_log
|
||||
service rsyslog restart
|
||||
fi
|
||||
if [ -f "/etc/chef/\\$node.done" ]; then
|
||||
chef-client --node-name \\$node --client_key /etc/chef/\\$node.pem &>> /tmp/chef.log
|
||||
else
|
||||
chef-client --node-name \\$node --client_key /etc/chef/\\$node.pem -L /var/log/chef/\\$node/chef-client.log &>> /tmp/chef.log
|
||||
fi
|
||||
if [ "\\$?" != "0" ]; then
|
||||
echo "chef-client --node-name \\$node run failed" &>> /tmp/chef.log
|
||||
let all_nodes_success=0
|
||||
else
|
||||
echo "chef-client --node-name \\$node run success" &>> /tmp/chef.log
|
||||
touch /etc/chef/\\$node.done
|
||||
fi
|
||||
done
|
||||
if [ \\$all_nodes_success -eq 0 ]; then
|
||||
sleep 1m
|
||||
else
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
EOF
|
||||
chmod +x /etc/chef/run.sh
|
||||
|
@ -17,9 +17,6 @@ no_proxy '$ignore_proxy'
|
||||
ENV['no_proxy'] = '$ignore_proxy'
|
||||
ENV['NO_PROXY'] = '$ignore_proxy'
|
||||
#end if
|
||||
#if $getVar('chef_node_name', '') != ""
|
||||
node_name '$chef_node_name'
|
||||
#end if
|
||||
validation_client_name 'chef-validator'
|
||||
json_attribs nil
|
||||
pid_file '/var/run/chef-client.pid'
|
||||
|
13
cobbler/snippets/kickstart_knife.rb
Normal file
13
cobbler/snippets/kickstart_knife.rb
Normal file
@ -0,0 +1,13 @@
|
||||
mkdir -p /root/.chef
|
||||
cat << EOL > /root/.chef/knife.rb
|
||||
log_level :info
|
||||
log_location '/dev/null'
|
||||
#if $getVar('chef_url', '') != ""
|
||||
chef_server_url '$chef_url'
|
||||
#end if
|
||||
node_name 'admin'
|
||||
client_key '/etc/chef/admin.pem'
|
||||
validation_client_name 'chef-validator'
|
||||
validation_key '/etc/chef/validation.pem'
|
||||
syntax_check_cache_path '/root/.chef/syntax_check_cache'
|
||||
EOL
|
@ -1,5 +1,7 @@
|
||||
#set hostname=$getVar('hostname',None)
|
||||
#set partition = $getVar('partition', None)
|
||||
#set partition_size = $getVar('partition_size', None)
|
||||
#set partition_maxsize = $getVar('partition_maxsize', None)
|
||||
|
||||
#if $hostname == None
|
||||
#set $vgname = "VolGroup00"
|
||||
@ -32,7 +34,7 @@ do
|
||||
shift 2
|
||||
done
|
||||
for key in \${!disk_mapping[@]}; do
|
||||
echo "\$key => \${disk_mapping[\$key]}" >> /tmp/log
|
||||
echo "disk mapping \$key => \${disk_mapping[\$key]}" >> /tmp/log
|
||||
done
|
||||
|
||||
declare -A disks
|
||||
@ -46,10 +48,9 @@ let found_disk=0
|
||||
if [[ x"\${disk_mapping[\$1]}" == x"" ]]; then
|
||||
echo "ignore disk \$1 since it is not in disk_mapping" >> /tmp/log
|
||||
else
|
||||
#if $getVar('partitions_only','') != ""
|
||||
#if $getVar('partitions_only', '') != ""
|
||||
#for $partition_only in $partitions_only.split(',')
|
||||
if expr match "\$1" "$partition_only"; then
|
||||
disks[\$found_disk_offset]=\$1
|
||||
let found_disk=1
|
||||
else
|
||||
echo "disk \$1 does not match $partition_only" >> /tmp/log
|
||||
@ -61,14 +62,18 @@ else
|
||||
fi
|
||||
if [ \$found_disk -gt 0 ]; then
|
||||
echo "add disk \$1 in partitioning list" >> /tmp/log
|
||||
#if $getVar('partition_by_path', '0') != "0"
|
||||
disks[\$found_disk_offset]=/dev/disk/by-path/\${disk_mapping[\$1]}
|
||||
#else
|
||||
disks[\$found_disk_offset]=\$1
|
||||
#end if
|
||||
let found_disk_offset=\$found_disk_offset+1
|
||||
fi
|
||||
let disk_offset=\$disk_offset+1
|
||||
shift 2
|
||||
done
|
||||
echo "disks \${disks[@]}" >> /tmp/log
|
||||
#if $getVar('sort_disks', '') != ""
|
||||
#if $getVar('sort_disks', '0') != "0"
|
||||
sorted_disks=(\$(printf '%s\n' \${disks[@]} | sort))
|
||||
#else
|
||||
sorted_disks=(\${disks[@]})
|
||||
@ -87,17 +92,137 @@ sorted_disks=(\${@:1:$disk_num})
|
||||
echo "sorted disks for $disk_num disks: \${sorted_disks[@]}" >> /tmp/log
|
||||
#end if
|
||||
let disk_nums=\${#sorted_disks[@]}
|
||||
sorted_disks_str=""
|
||||
for disk in \${sorted_disks[@]}; do
|
||||
sorted_disks_str="\${sorted_disks_str},\${disk}"
|
||||
done
|
||||
|
||||
echo "clearpart --all --initlabel" > /tmp/part-include
|
||||
|
||||
#if $getVar('keep_old_partitions', '0') != "0"
|
||||
#if $getVar('partitions_only','') != ""
|
||||
echo "ignoredisk --only-use=$partitions_only" >> /tmp/part-include
|
||||
#end if
|
||||
echo "only partition \$sorted_disks_str" >> /tmp/log
|
||||
echo "ignoredisk --only-use=\$sorted_disks_str" >> /tmp/part-include
|
||||
#end if
|
||||
|
||||
echo "part /boot --fstype ext3 --size=500 --ondisk=\${sorted_disks[0]} --asprimary" >> /tmp/part-include
|
||||
echo "part swap --recommended --maxsize=128000 --ondisk=\${sorted_disks[0]}" >> /tmp/part-include
|
||||
declare -A partitions_percentage
|
||||
declare -A partitions_name
|
||||
declare -A partitions_size
|
||||
declare -A partitions_maxsize
|
||||
|
||||
#if $partition != None
|
||||
#set vol_sizes = [part.strip() for part in $partition.split(';') if part.strip()]
|
||||
#for vol_and_size in $vol_sizes
|
||||
#set vol, vol_size = $vol_and_size.split(' ', 1)
|
||||
#set vol = $vol.strip()
|
||||
#if $vol == '/'
|
||||
#set volname = 'root'
|
||||
#elif $vol == 'swap'
|
||||
#set volname = 'swap'
|
||||
#elif $vol.startswith('/')
|
||||
#set volname = $vol[1:].replace('/', '_')
|
||||
#else
|
||||
#set volname = ''
|
||||
# $vol is not starts with /
|
||||
#end if
|
||||
partitions_name[$vol]=$volname
|
||||
#set vol_size = $vol_size.strip()
|
||||
#if $vol_size.endswith('%'):
|
||||
#set vol_percent = $vol_size[:-1]
|
||||
partitions_percentage[$vol]=${vol_percent}
|
||||
#else
|
||||
#if $vol_size.endswith('K')
|
||||
#set vol_min_size = $int($vol_size[:-1]) / 1000
|
||||
#elif $vol_size.endswith('M')
|
||||
#set vol_min_size = $int($vol_size[:-1])
|
||||
#elif $vol_size.endswith('G')
|
||||
#set vol_min_size = $int($vol_size[:-1]) * 1000
|
||||
#elif $vol_size.endswith('T')
|
||||
#set vol_min_size = $int($vol_size[:-1]) * 1000000
|
||||
#else
|
||||
#set vol_min_size = $int($vol_size)
|
||||
#end if
|
||||
partitions_size[$vol]=${vol_min_size}
|
||||
#end if
|
||||
#end for
|
||||
#end if
|
||||
|
||||
#if $partition_size != None
|
||||
#set vol_sizes = [part.strip() for part in $partition_size.split(';') if part.strip()]
|
||||
#for vol_and_size in $vol_sizes
|
||||
#set vol, vol_size = $vol_and_size.split(' ', 1)
|
||||
#set vol = $vol.strip()
|
||||
#if $vol_size.endswith('K')
|
||||
#set vol_min_size = $int($vol_size[:-1]) / 1000
|
||||
#elif $vol_size.endswith('M')
|
||||
#set vol_min_size = $int($vol_size[:-1])
|
||||
#elif $vol_size.endswith('G')
|
||||
#set vol_min_size = $int($vol_size[:-1]) * 1000
|
||||
#elif $vol_size.endswith('T')
|
||||
#set vol_min_size = $int($vol_size[:-1]) * 1000000
|
||||
#else
|
||||
#set vol_min_size = $int($vol_size)
|
||||
#end if
|
||||
partitions_size[$vol]=${vol_min_size}
|
||||
#end for
|
||||
#end if
|
||||
|
||||
#if $partition_maxsize != None
|
||||
#set vol_sizes = [part.strip() for part in $partition_maxsize.split(';') if part.strip()]
|
||||
#for vol_and_size in $vol_sizes
|
||||
#set vol, vol_size = $vol_and_size.split(' ', 1)
|
||||
#set vol = $vol.strip()
|
||||
#if $vol_size.endswith('K')
|
||||
#set vol_max_size = $int($vol_size[:-1]) / 1000
|
||||
#elif $vol_size.endswith('M')
|
||||
#set vol_max_size = $int($vol_size[:-1])
|
||||
#elif $vol_size.endswith('G')
|
||||
#set vol_max_size = $int($vol_size[:-1]) * 1000
|
||||
#elif $vol_size.endswith('T')
|
||||
#set vol_max_size = $int($vol_size[:-1]) * 1000000
|
||||
#else
|
||||
#set vol_max_size = $int($vol_size)
|
||||
#end if
|
||||
partitions_maxsize[$vol]=${vol_max_size}
|
||||
#end for
|
||||
#end if
|
||||
|
||||
default_partition=$getVar('default_partition', '/')
|
||||
partition_fstype=$getVar('partition_fstype', 'ext3')
|
||||
|
||||
for key in \${!partitions_name[@]}; do
|
||||
echo "partition names \$key => \${partitions_name[\$key]}" >> /tmp/log
|
||||
done
|
||||
|
||||
for key in \${!partitions_percentage[@]}; do
|
||||
echo "partition percentage \$key => \${partitions_percentage[\$key]}" >> /tmp/log
|
||||
done
|
||||
|
||||
for key in \${!partitions_size[@]}; do
|
||||
echo "partition min size \$key => \${partitions_size[\$key]}" >> /tmp/log
|
||||
done
|
||||
|
||||
echo "default partition \${default_partition}" >> /tmp/log
|
||||
echo "partition fstype \${partition_fstype}" >> /tmp/log
|
||||
|
||||
for key in \${!partitions_maxsize[@]}; do
|
||||
echo "partition max size \$key => \${partitions_maxsize[\$key]}" >> /tmp/log
|
||||
done
|
||||
|
||||
partition_size=\${partitions_size[/boot]:-500}
|
||||
unset \${partitions_name[/boot]}
|
||||
echo "part /boot --fstype=\${partition_fstype} --size=\${partition_size} --ondisk=\${sorted_disks[0]} --asprimary" >> /tmp/part-include
|
||||
partition_size=\${partitions_size[swap]:-0}
|
||||
if [[ "\$partition_size" == "0" ]]; then
|
||||
partition_maxsize=\${partitions_maxsize[swap]:-128000}
|
||||
echo "part swap --recommended --maxsize=\${partition_maxsize} --ondisk=\${sorted_disks[0]}" >> /tmp/part-include
|
||||
else
|
||||
echo "part swap --size=\${partition_size} --ondisk=\${sorted_disks[0]}" >> /tmp/part-include
|
||||
fi
|
||||
unset \${partitions_name[swap]}
|
||||
|
||||
if [[ x"\${partitions_name[/]}" == x"" ]]; then
|
||||
partitions_name[/]="root"
|
||||
fi
|
||||
|
||||
vggroup=''
|
||||
let disk_offset=0
|
||||
@ -112,24 +237,41 @@ done
|
||||
|
||||
echo "volgroup $vgname \$vggroup" >> /tmp/part-include
|
||||
|
||||
echo "logvol / --fstype ext3 --vgname=$vgname --size=1 --grow --name=rootvol" >> /tmp/part-include
|
||||
declare -A sorted_partitions
|
||||
sorted_partitions[0]=\${default_partition}
|
||||
partition_offset=1
|
||||
for key in \${!partitions_name[@]}; do
|
||||
if [[ "\$key" != "\${default_partition}" ]]; then
|
||||
sorted_partitions[\${partition_offset}]=\$key
|
||||
let partition_offset=\${partition_offset}+1
|
||||
fi
|
||||
done
|
||||
|
||||
#if $partition != None
|
||||
#set vol_sizes = [part.strip() for part in $partition.split(';') if part.strip()]
|
||||
#for vol_and_size in vol_sizes
|
||||
#set vol, vol_size = $vol_and_size.split(' ', 1)
|
||||
#set vol = $vol.strip()
|
||||
#set vol_size = $vol_size.strip()
|
||||
#if $vol.startswith('/')
|
||||
#set volname = $vol[1:]
|
||||
#if $vol_size.endswith('%'):
|
||||
#set vol_percent = vol_size[:-1]
|
||||
echo "logvol $vol --fstype ext3 --vgname=$vgname --size=1 --grow --percent=$vol_percent --name=${volname}vol" >> /tmp/part-include
|
||||
#else
|
||||
echo "logvol $vol --vgname=$vgname --fstype ext3 --size=$vol_size --name=${volname}vol" >> /tmp/part-include
|
||||
#end if
|
||||
#else
|
||||
# $vol is not starts with /
|
||||
#end if
|
||||
#end for
|
||||
#end if
|
||||
for key in \${sorted_partitions[@]}; do
|
||||
partition_name=\${partitions_name[\$key]}
|
||||
if [[ "\$key" == "\${default_partition}" ]]; then
|
||||
grow_param="--grow"
|
||||
else
|
||||
grow_param=""
|
||||
fi
|
||||
partition_percentage=\${partitions_percentage[\$key]}
|
||||
if [[ x"\${partition_percentage}" != x"" ]]; then
|
||||
percentage_param="--percent=\${partition_percentage}"
|
||||
grow_param="--grow"
|
||||
else
|
||||
percentage_param=""
|
||||
fi
|
||||
partition_size=\${partitions_size[\$key]}
|
||||
if [[ x"\${partition_size}" != x"" ]]; then
|
||||
size_param="--size=\${partition_size}"
|
||||
else
|
||||
size_param="--size=1"
|
||||
fi
|
||||
partition_maxsize=\${partitions_maxsize[\$key]}
|
||||
if [[ x"\${partition_maxsize}" != x"" ]]; then
|
||||
maxsize_param="--maxsize=\${partition_maxsize}"
|
||||
else
|
||||
maxsize_param=""
|
||||
fi
|
||||
echo "logvol \$key --fstype=\${partition_fstype} --vgname=$vgname \${percentage_param} \${size_param} \${maxsize_param} \${grow_param} --name=\${partition_name}vol" >> /tmp/part-include
|
||||
done
|
||||
|
Loading…
x
Reference in New Issue
Block a user