码迷,mamicode.com
首页 > 其他好文 > 详细

ansible学习之--简单学习笔记一

时间:2015-07-10 13:29:46      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:ansible   playbook   加密   

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脚本的结果如下

技术分享





版权声明:本文为博主原创文章,未经博主允许不得转载。

ansible学习之--简单学习笔记一

标签:ansible   playbook   加密   

原文地址:http://blog.csdn.net/viease/article/details/46828677

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!