Custom file management
If you need to, you can copy custom files or even create files with content in YAML templates using a set of list variables. You can use this feature to install private keys and certificates stored as YAML text blocks in a file encrypted with ansible-vault which is unlocked during Ansible run.
Each element of the file list is a dict with specific parameters:
srcRequired, unless
contentis specified. Path to a file on the Ansible Controller, which will be copied to the remote host.contentRequired, unless
srcis specified. A YAML text block or a Jinja variable, contents of which will be copied to the specified file on the remote host.destRequired. Path to the destination file on the remote host.
ownerOwner of the created file, by default
root.groupFile group, depending on the file type it will be
root(for public files) or a group specified by thepki_private_groupvariable, usuallyssl-cert(for private files).modeFile permissions, by default public files are copied with permissions
644and private files will have640permissions.forceBoolean. If
True(default), an existing file will be replaced with the specified file or contents.
There are multiple list variables which can be used on multiple inventory levels:
all hosts in the inventory: -
pki_private_files-pki_public_fileshosts in specific inventory group: -
pki_group_private_files-pki_group_public_filesspecific hosts: -
pki_host_private_files-pki_host_public_files
The private files will be copied before PKI realms are created, so that you can provide private keys if you want to. Public files will be copied after PKI realms are created, and internal certificates are signed.
Examples
Install a custom private key from a Jinja variable on all hosts:
pki_private_files:
- content: '{{ custom_variable }}'
dest: '/etc/pki/realms/domain/private/key.pem'