使用Ansible自动设置加密分区

时间:2014-07-31 07:57:57

标签: linux encryption ansible ansible-playbook truecrypt

我正在寻找一种在Ubuntu / Debian Linux服务器上自动使用Ansible设置加密分区的方法。

  • 假设具有现有根的计算机填满整个磁盘

  • 从此分区中删除一块并从中创建一个新分区

  • 使用LUKS或Truecrypt加密分区

  • 将密码短语作为剧本的输入

我是Ansible的新手,所以如果有人能指出我的起点(现有磁盘分区角色,加密磁盘角色等)。我可以用Ansible驱动fdisk吗?如何确保角色不会尝试两次创建分区(再次运行配置时)。

2 个答案:

答案 0 :(得分:4)

Writing a Ansible role which does this is not as easy as it might seem when you want to do it right (e.g. idempotent and be robust). I know that because I just wrote/rewrote one :) https://github.com/debops-contrib/ansible-cryptsetup It is able to handle 2 of your 3 wanted features: Encrypt the partition using LUKS or Truecrypt Taking passphrase as input for the playbook. I did take a different path using keyfiles which did better fit my use case. Passphrases might be supported in the future. For now you can just write the passphrase to a file and specify that as keyfile. I decided against including support to create partitions to the role itself to keep complexity down.

答案 1 :(得分:2)

虽然我没有亲自编写任何剧本来完成你想要做的事情,但这里有一些资源可能有所帮助:

您可以使用几个Ansible模块来管理分区:

lvol - Configure LVM logical volumes

lvg - Configure LVM volume groups

可能还有一些对您有用的系统模块here

没有专门针对fdisk的ansible模块,但您仍然可以使用命令或shell模块运行fdisk命令。如果你走这条路,你将不得不弄清楚如何使它成为幂等的。

如果您正在寻找角色,我通常会推荐Ansible Galaxy,但在快速搜索中,我无法找到与您尝试的相关的任何角色。

我没有专门知道使用LUKS或Truecrypt的Ansible模块,但您仍然可以使用命令或shell模块运行这些任务。

我能够在this playbook中找到一个不错的磁盘加密示例。该剧本通过将其作为变量传递来处理密码。有几种方法可以处理剧本中的变量。我建议您阅读variables上的Ansible文档。如果要将密码存储为变量,还可以使用Ansible Vault加密变量文件。