Chapter 6. Restoring IdM servers using Ansible playbooks
Using the ipabackup Ansible role, you can automate restoring an IdM server from a backup and transferring backup files between servers and your Ansible controller.
6.1. Creating an Ansible inventory file for IdM 링크 복사링크가 클립보드에 복사되었습니다!
When working with Ansible, it is good practice to create, in your home directory, a subdirectory dedicated to Ansible playbooks that you copy and adapt from the /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/* and /usr/share/doc/rhel-system-roles/* subdirectories. This practice has the following advantages:
- You can find all your playbooks in one place.
-
You can run your playbooks without invoking
rootprivileges.
Procedure
Create a directory for your Ansible configuration and playbooks in your home directory:
mkdir ~/MyPlaybooks/
$ mkdir ~/MyPlaybooks/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change into the ~/MyPlaybooks/ directory:
cd ~/MyPlaybooks
$ cd ~/MyPlaybooksCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the ~/MyPlaybooks/ansible.cfg file with the following content:
[defaults] inventory = /home/<username>/MyPlaybooks/inventory [privilege_escalation] become=True
[defaults] inventory = /home/<username>/MyPlaybooks/inventory [privilege_escalation] become=TrueCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the ~/MyPlaybooks/inventory file with the following content:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This configuration defines two host groups, eu and us, for hosts in these locations. Additionally, this configuration defines the ipaserver host group, which contains all hosts from the eu and us groups.
6.2. Using Ansible to restore an IdM server from a backup stored on the server 링크 복사링크가 클립보드에 복사되었습니다!
You can use an Ansible playbook to restore an IdM server from a backup stored on that host.
Prerequisites
On the control node:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica. - You know the LDAP Directory Manager password.
Procedure
Navigate to the
~/MyPlaybooks/directory:cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
restore-server.ymlfile located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooksdirectory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/restore-server.yml restore-my-server.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/restore-server.yml restore-my-server.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
restore-my-server.ymlAnsible playbook file for editing. Adapt the file by setting the following variables:
-
Set the
hostsvariable to a host group from your inventory file. In this example, set it to theipaserverhost group. -
Set the
ipabackup_namevariable to the name of theipabackupto restore. Set the
ipabackup_passwordvariable to the LDAP Directory Manager password.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Set the
Save the file.
For details about variables and example playbooks in the FreeIPA Ansible collection, see the
/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/README.mdfile and the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/directory on the control node.Run the Ansible playbook specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory restore-my-server.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory restore-my-server.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
6.3. Using Ansible to restore an IdM server from a backup stored on your Ansible controller 링크 복사링크가 클립보드에 복사되었습니다!
You can use an Ansible playbook to restore an IdM server from a backup stored on your Ansible controller.
Prerequisites
On the control node:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica. - You know the LDAP Directory Manager password.
Procedure
Navigate to the
~/MyPlaybooks/directory:cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
restore-server-from-controller.ymlfile located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooksdirectory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/restore-server-from-controller.yml restore-my-server-from-my-controller.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/restore-server-from-controller.yml restore-my-server-from-my-controller.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
restore-my-server-from-my-controller.ymlfile for editing. Adapt the file by setting the following variables:
-
Set the
hostsvariable to a host group from your inventory file. In this example, set it to theipaserverhost group. -
Set the
ipabackup_namevariable to the name of theipabackupto restore. Set the
ipabackup_passwordvariable to the LDAP Directory Manager password.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Set the
Save the file.
For details about variables and example playbooks in the FreeIPA Ansible collection, see the
/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/README.mdfile and the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/directory on the control node.Run the Ansible playbook, specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory restore-my-server-from-my-controller.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory restore-my-server-from-my-controller.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
6.4. Using Ansible to copy a backup of an IdM server to your Ansible controller 링크 복사링크가 클립보드에 복사되었습니다!
You can use an Ansible playbook to copy an existing backup file of an IdM server from the IdM server to your Ansible controller.
Prerequisites
On the control node:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica.
Procedure
To store the backups, create a subdirectory in your home directory on the Ansible controller.
mkdir ~/ipabackups
$ mkdir ~/ipabackupsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Navigate to the
~/MyPlaybooks/directory:cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
copy-backup-from-server.ymlfile located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooksdirectory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/copy-backup-from-server.yml copy-backup-from-my-server-to-my-controller.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/copy-backup-from-server.yml copy-backup-from-my-server-to-my-controller.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
copy-my-backup-from-my-server-to-my-controller.ymlfile for editing. Adapt the file by setting the following variables:
-
Set the
hostsvariable to a host group from your inventory file. In this example, set it to theipaserverhost group. -
Set the
ipabackup_namevariable to the name of theipabackupon your IdM server to copy to your Ansible controller. By default, backups are stored in the present working directory of the Ansible controller. To specify the directory you created in Step 1, add the
ipabackup_controller_pathvariable and set it to the/home/user/ipabackupsdirectory.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Set the
Save the file.
For details about variables and example playbooks in the FreeIPA Ansible collection, see the
/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/README.mdfile and the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/directory on the control node.Run the Ansible playbook, specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory copy-backup-from-my-server-to-my-controller.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory copy-backup-from-my-server-to-my-controller.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteTo copy all IdM backups to your controller, set the
ipabackup_namevariable in the Ansible playbook toall:vars: ipabackup_name: all ipabackup_to_controller: truevars: ipabackup_name: all ipabackup_to_controller: trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow For an example, see the
copy-all-backups-from-server.ymlAnsible playbook in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooksdirectory.
Verification
Verify your backup is in the
/home/user/ipabackupsdirectory on your Ansible controller:ls /home/user/ipabackups server.idm.example.com_ipa-full-2021-04-30-13-12-00
[user@controller ~]$ ls /home/user/ipabackups server.idm.example.com_ipa-full-2021-04-30-13-12-00Copy to Clipboard Copied! Toggle word wrap Toggle overflow
You can use an Ansible playbook to copy an existing backup file of an IdM server from your Ansible controller to the IdM server.
Prerequisites
You have configured your Ansible control node to meet the following requirements:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica.
Procedure
Navigate to the
~/MyPlaybooks/directory:cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
copy-backup-from-controller.ymlfile located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooksdirectory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/copy-backup-from-controller.yml copy-backup-from-my-controller-to-my-server.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/copy-backup-from-controller.yml copy-backup-from-my-controller-to-my-server.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
copy-my-backup-from-my-controller-to-my-server.ymlfile for editing. Adapt the file by setting the following variables:
-
Set the
hostsvariable to a host group from your inventory file. In this example, set it to theipaserverhost group. Set the
ipabackup_namevariable to the name of theipabackupon your Ansible controller to copy to the IdM server.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Set the
Save the file.
For details about variables and example playbooks in the FreeIPA Ansible collection, see the
/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/README.mdfile and the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/directory on the control node.Run the Ansible playbook, specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory copy-backup-from-my-controller-to-my-server.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory copy-backup-from-my-controller-to-my-server.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
6.6. Using Ansible to remove a backup from an IdM server 링크 복사링크가 클립보드에 복사되었습니다!
You can use an Ansible playbook to automate the removal of old or unnecessary backup files from an IdM server.
Prerequisites
On the control node:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica.
Procedure
Navigate to the ~/MyPlaybooks/ directory:
cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a copy of the
remove-backup-from-server.ymlfile located in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooksdirectory:cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/remove-backup-from-server.yml remove-backup-from-my-server.yml
$ cp /usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/remove-backup-from-server.yml remove-backup-from-my-server.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Open the
remove-backup-from-my-server.ymlfile for editing. Adapt the file by setting the following variables:
-
Set the
hostsvariable to a host group from your inventory file. In this example, set it to theipaserverhost group. Set the
ipabackup_namevariable to the name of theipabackupto remove from your IdM server.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Set the
Save the file.
For details about variables and example playbooks in the FreeIPA Ansible collection, see the
/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/README.mdfile and the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/directory on the control node.Run the Ansible playbook, specifying the inventory file and the playbook file:
ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory remove-backup-from-my-server.yml
$ ansible-playbook --vault-password-file=password_file -v -i ~/MyPlaybooks/inventory remove-backup-from-my-server.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteTo remove all IdM backups from the IdM server, set the
ipabackup_namevariable in the Ansible playbook toall:vars: ipabackup_name: allvars: ipabackup_name: allCopy to Clipboard Copied! Toggle word wrap Toggle overflow For an example, see the
remove-all-backups-from-server.ymlAnsible playbook in the/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooksdirectory.