diff --git a/changelogs/fragments/update_pattern_specifications.yml b/changelogs/fragments/update_pattern_specifications.yml new file mode 100644 index 0000000..004fe2b --- /dev/null +++ b/changelogs/fragments/update_pattern_specifications.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - update pattern specification and default filename and path handling. diff --git a/extensions/patterns/backup/template_surveys/backup.yaml b/extensions/patterns/backup/template_surveys/backup.yaml index 80dead9..e9a1358 100644 --- a/extensions/patterns/backup/template_surveys/backup.yaml +++ b/extensions/patterns/backup/template_surveys/backup.yaml @@ -4,40 +4,46 @@ description: "Survey to configure network backup options" spec: - type: "multiplechoice" question_name: "Backup Type" - question_description: "Select the type of backup" + question_description: "Select the type of backup to perform — a full or differential (diff) backup." variable: "backup_type" choices: - "full" - "diff" - required: true + required: false default: "full" + - type: "text" + question_name: "GitHub Username" + question_description: "Enter your GitHub username associated with the target repository." + variable: "gh_user" + required: true + + - type: "text" + question_name: "GitHub Email" + question_description: "Enter the email address linked to your GitHub account that owns the target repository." + variable: "gh_email" + required: false + - type: "text" question_name: "GitHub Repository URL" - question_description: "URL of the GitHub repository for storing the backup" - variable: "GH_REPO" + question_description: "Enter the GitHub repository URL you want to use." + variable: "gh_url" required: true - type: "password" question_name: "GitHub Token" - question_description: "Personal access token for GitHub repository" - variable: "GH_TOKEN" + question_description: "Enter your GitHub personal access token with access to the target repository." + variable: "gh_token" required: true - type: "text" - question_name: "GitHub Username" - question_description: "GitHub username for the repository" - variable: "GH_USER" - required: true - - - type: "text" - question_name: "GitHub Email" - question_description: "GitHub email associated with the repository" - variable: "GH_EMAIL" - required: true - + question_name: "Path" + question_description: "Specify the relative path inside your GitHub repository where the backup file should be saved. If left blank, the default role path () will be used." + variable: "path" + required: false + - type: "text" - question_name: "Backup File Name" - question_description: "Name of the backup file (optional). If not provided, a timestamp will be used." - variable: "backup_file_name" + question_name: "Backup Filename" + question_description: "Provide a name for the backup file (e.g., device_backup.txt). If left blank, a default filename will be generated using the device name and timestamp." + variable: "filename" required: false diff --git a/extensions/patterns/restore/template_surveys/restore.yaml b/extensions/patterns/restore/template_surveys/restore.yaml index 485ba01..0329d6a 100644 --- a/extensions/patterns/restore/template_surveys/restore.yaml +++ b/extensions/patterns/restore/template_surveys/restore.yaml @@ -4,18 +4,24 @@ description: "Survey to configure network restore options" spec: - type: "text" question_name: "GitHub Repository URL" - question_description: "URL of the GitHub repository containing the backup" - variable: "GH_REPO" + question_description: "Enter the GitHub repository URL you want to use." + variable: "gh_url" required: true - type: "password" question_name: "GitHub Token" - question_description: "Personal access token for GitHub repository" - variable: "GH_TOKEN" + question_description: "Enter your GitHub personal access token with access to the target repository." + variable: "gh_token" required: true - type: "text" - question_name: "File Path for Restore" - question_description: "Path to the specific backup file in the GitHub repository" - variable: "file_path" + question_name: "Path" + question_description: "Specify the relative path inside your GitHub repository where the backup file is saved." + variable: "path" + required: true + + - type: "text" + question_name: "Backup Filename" + question_description: "Provide the backup file name" + variable: "filename" required: true diff --git a/roles/backup/tasks/backup.yaml b/roles/backup/tasks/backup.yaml index 916ea3a..57e5c5d 100644 --- a/roles/backup/tasks/backup.yaml +++ b/roles/backup/tasks/backup.yaml @@ -15,14 +15,17 @@ - name: Get file name ansible.builtin.set_fact: - network_backup_path: "{{ network_backup_path_root }}/{{ data_store.scm.origin.path }}" + network_backup_path: "{{ network_backup_path_root }}/{{ data_store.scm.origin.path | default(role_path, true)}}" when: data_store['scm']['origin'] is defined -- name: Get file name +- name: Get timestamp ansible.builtin.set_fact: - network_backup_filename: "{{ data_store.scm.origin.filename }}" - when: data_store['scm']['origin'] is defined + timestamp: "{{ lookup('pipe', 'date +%Y-%m-%d_%H-%M-%S') }}" +- name: Set default filename + ansible.builtin.set_fact: + network_backup_filename: >- + {{ data_store.scm.origin.filename | default(inventory_hostname ~ '_' ~ timestamp ~ '.txt', true) }} - name: Include tasks ansible.builtin.include_tasks: network.yaml