1.利用dm-crypt来创建加密文件系统。编写shell脚本
2.编写ansible,playbook文件
3.编写python脚本
首先编写shell脚本
#!/bin/sh sudo apt-get install dmsetup cryptsetup sudo modprobe dm-crypt echo "dd if=/dev/zero of=/home/prod/secret.img bs=1M count=100" sudo dd if=/dev/zero of=/home/prod/secret.img bs=1M count=100 echo "----------------------------------------------------------" echo "losetup /dev/loop0 ~/secret.img" sudo losetup /dev/loop0 /home/prod/secret.img echo "----------------------------------------------------------" sudo losetup /dev/loop0 echo "----------------------------------------------------------" echo "cryptsetup -y create myEncryptedFilesystem /dev/loop0" sudo cryptsetup -y create myEncryptedFilesystem /dev/loop0 echo "----------------------------------------------------------" sudo dmsetup ls echo "----------------------------------------------------------" echo "mkfs.ext3 /dev/mapper/myEncryptedFilesystem" sudo mkfs.ext3 /dev/mapper/myEncryptedFilesystem echo "----------------------------------------------------------" sudo mkdir /mnt/myEncryptedFilesystem echo "----------------------------------------------------------" echo "mount /dev/mapper/myEncryptedFilesystem /mnt/myEncryptedFilesystem" sudo mount /dev/mapper/myEncryptedFilesystem /mnt/myEncryptedFilesystem echo "----------------------------------------------------------" sudo df -h /mnt/myEncryptedFilesystem
编写playbook文件
--- - hosts: cmdb user: prod sudo: True tasks: - name: install dm-crypt action: command sh /home/prod/svnrepos/uninstall.sh
编写python脚本
import commands (status, output) = commands.getstatusoutput('ansible-playbook playbook.yml') print status, output
执行python脚本的结果如下
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-26 16:35:40