mirror of
https://git.ecdf.ed.ac.uk/win_automation/windows-ansible.git
synced 2026-10-26 12:57:21 +00:00
new transfer tasks and fixed permissions
This commit is contained in:
1 parent
f1541c6f29
commit
dc1afab15f
7 files changed
+122
-18
No files matched your search
@@ -1 +1 @@
|
||||
scheduled_transfer_export_v1.3.ps1
|
||||
scheduled_transfer_export_v2.0.ps1
|
||||
@@ -0,0 +1,40 @@
|
||||
function Main {
|
||||
$log_file="T:\Logs\Export-Log.txt"
|
||||
|
||||
$export_dirs=Get-ChildItem -Path "S:\" -Directory -Recurse -Filter "Export"
|
||||
|
||||
foreach($export_dir in $export_dirs) {
|
||||
$full_path="$($export_dir.FullName)"
|
||||
$parent_dir="$($export_dir.Parent)"
|
||||
|
||||
$files=Get-ChildItem -path $full_path -File
|
||||
|
||||
foreach($file in $files) {
|
||||
$file_path="$($file.FullName)"
|
||||
|
||||
$destination="T:\Export\$parent_dir\"
|
||||
|
||||
$size=Format-FileSize(($file_path).length)
|
||||
|
||||
Move-Item -Path $file_path -Destination $destination
|
||||
|
||||
$date=Get-Date -UFormat "[%d/%b/%y %T]"
|
||||
$log_line="{0} {1} -> {2} [{3}]"-f $date, $file_path, $destination, $size
|
||||
|
||||
Write-Host $log_line
|
||||
$log_line | out-file $log_file -Append
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Format-FileSize() {
|
||||
Param ([int64]$size)
|
||||
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
|
||||
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
|
||||
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
|
||||
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)}
|
||||
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)}
|
||||
Else {[string]::Format("0B", $size)}
|
||||
}
|
||||
|
||||
Main
|
||||
@@ -1 +1 @@
|
||||
scheduled_transfer_import_v1.3.ps1
|
||||
scheduled_transfer_import_v2.0.ps1
|
||||
@@ -0,0 +1,43 @@
|
||||
function Main {
|
||||
$import_dir="T:\Import\"
|
||||
$log_file="T:\Logs\Import-Log.txt"
|
||||
|
||||
$files=Get-ChildItem -Path $import_dir -File -Recurse -Force -Exclude ".*"
|
||||
|
||||
foreach($file in $files) {
|
||||
$file_name="$($file.Name)"
|
||||
$parent_dir="$($file.Directory.Name)"
|
||||
|
||||
$Destination="S:\" + "$parent_dir" + "\import"
|
||||
|
||||
$size=Format-FileSize(($file).length)
|
||||
|
||||
$date=Get-Date -UFormat "[%d/%b/%y %T]"
|
||||
|
||||
if([System.IO.File]::Exists("$Destination\$file_name")) {
|
||||
$log_line="{0} {1} already exists at {2}"-f $date, $file_name, $destination, $size
|
||||
Write-Host $log_line
|
||||
$log_line | out-file $log_file -Append
|
||||
continue;
|
||||
}
|
||||
|
||||
Move-Item -path $file -Destination $Destination
|
||||
|
||||
$log_line="{0} {1} -> {2} [{3}]"-f $date, $file, $destination, $size
|
||||
|
||||
Write-Host $log_line
|
||||
$log_line | out-file $log_file -Append
|
||||
}
|
||||
}
|
||||
|
||||
function Format-FileSize() {
|
||||
Param ([int64]$size)
|
||||
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
|
||||
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
|
||||
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
|
||||
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)}
|
||||
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)}
|
||||
Else {[string]::Format("0B", $size)}
|
||||
}
|
||||
|
||||
Main
|
||||
@@ -74,22 +74,18 @@
|
||||
file_system: NTFS
|
||||
new_label: "{{ filetransfer_volume_label }}"
|
||||
|
||||
- name: Create Import and Export directories in T drive for File Transfer script
|
||||
- name: Create Import, Export, and Logs directories in T drive for File Transfer script
|
||||
win_file:
|
||||
path: "T:\\{{ item }}"
|
||||
state: directory
|
||||
with_items: ["Import", "Export"]
|
||||
|
||||
- name: Create logs directory in T drive
|
||||
win_file:
|
||||
path: "T:\\Logs"
|
||||
state: directory
|
||||
with_items: ["Import", "Export", "Logs"]
|
||||
|
||||
- name: Set permissions on logs folder on T drive
|
||||
win_acl:
|
||||
path: "T:\\logs"
|
||||
user: file-transfer
|
||||
path: "T:\\{{ item }}"
|
||||
user: "{{ win_project }}\\{{ filetransfer_user }}"
|
||||
type: allow
|
||||
rights: Read,Write,Modify
|
||||
state: present
|
||||
with_items: ["Import", "Export", "Logs"]
|
||||
when: inventory_hostname in groups['meta-name_fs01']
|
||||
@@ -1,4 +1,12 @@
|
||||
---
|
||||
- name: add user rights to file-transfer user
|
||||
tags: transfer_user_rights
|
||||
ansible.windows.win_user_right:
|
||||
name: SeBatchLogonRight
|
||||
users:
|
||||
- "{{ win_project }}\\{{ filetransfer_user }}"
|
||||
action: add
|
||||
|
||||
- name: Copy scripts to fileserver
|
||||
tags: copy_scheduled_tasks
|
||||
block:
|
||||
@@ -38,6 +46,9 @@
|
||||
start_boundary: "{{ task_start_time.stdout }}"
|
||||
repetition:
|
||||
interval: PT5M
|
||||
multiple_instances: 1
|
||||
run_level: highest
|
||||
start_when_available: true
|
||||
|
||||
- name: Create import scheduled task
|
||||
win_scheduled_task:
|
||||
@@ -55,4 +66,7 @@
|
||||
start_boundary: "{{ task_start_time.stdout }}"
|
||||
repetition:
|
||||
interval: PT5M
|
||||
multiple_instances: 1
|
||||
run_level: highest
|
||||
start_when_available: true
|
||||
when: inventory_hostname in groups['meta-name_fs01']
|
||||
@@ -24,13 +24,24 @@
|
||||
retries: 10
|
||||
delay: 10
|
||||
|
||||
- name: Add file-transfer user permissions to study folder
|
||||
win_acl:
|
||||
path: "{{ study_folder }}\\export"
|
||||
state: present
|
||||
type: allow
|
||||
user: file-transfer
|
||||
rights: 'FullControl'
|
||||
- name: file-transfer user permissions
|
||||
block:
|
||||
- name: Add file-transfer user permissions to study folder
|
||||
win_acl:
|
||||
path: "{{ study_folder }}"
|
||||
state: present
|
||||
type: allow
|
||||
user: file-transfer
|
||||
rights: 'Read,ReadAndExecute,ListDirectory'
|
||||
|
||||
- name: Add file-transfer user permissions to study folder
|
||||
win_acl:
|
||||
path: "{{ study_folder }}\\{{ item }}"
|
||||
state: present
|
||||
type: allow
|
||||
user: file-transfer
|
||||
rights: 'Modify,Write'
|
||||
loop: ["import", "export"]
|
||||
|
||||
- name: Remove Users permissions
|
||||
block:
|
||||
|
||||
Reference in new issue
Block a user