Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
debian12-deployment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COBALT
debian12-deployment
Commits
613abd82
Commit
613abd82
authored
1 month ago
by
Bram Veenboer
Browse files
Options
Downloads
Patches
Plain Diff
Add playbook to merge users
parent
90e3bd52
Branches
main
No related tags found
1 merge request
!6
Add playbook to merge users
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+7
-1
7 additions, 1 deletion
README.md
templates/merge_users.sh
+26
-0
26 additions, 0 deletions
templates/merge_users.sh
xx_merge_users.yml
+54
-0
54 additions, 0 deletions
xx_merge_users.yml
with
87 additions
and
1 deletion
README.md
+
7
−
1
View file @
613abd82
...
...
@@ -42,6 +42,7 @@ order:
-
`ansible-playbook 02_install_nvidia_driver_*.yml`
-
`ansible-playbook 03_install_mellanox_ofed.yml`
-
`ansible-playbook 04_install_slurm.yml`
-
`ansible-playbook xx_merge_users.yml`
### Playbook overview
...
...
@@ -63,5 +64,10 @@ order:
-
**03_install_mellanox_ofed.yml**
\
Installs Mellanox OFED drivers.
-
**04
\_
install_slurm.yml**
\
-
**04
_
install_slurm.yml**
\
Installs and configures SLURM for use with DAS-6.
-
**xx_merge_users.yml**
\
Merges the system users from the local machine with the users from DAS-6. This
playbook has number
`xx`
because it should preferably be ran periodically,
e.g. using cron.
This diff is collapsed.
Click to expand it.
templates/merge_users.sh
0 → 100644
+
26
−
0
View file @
613abd82
#!/bin/bash
set
-e
SOURCE_DIR
=
$1
DEST_DIR
=
$2
for
file
in
passwd group shadow
;
do
SOURCE_FILE
=
"
${
SOURCE_DIR
}
/
${
file
}
_src"
DEST_FILE
=
"
${
DEST_DIR
}
/
${
file
}
"
MERGED_FILE
=
"
${
SOURCE_DIR
}
/merged_
${
file
}
"
# Ensure files exist
if
[[
!
-f
"
$SOURCE_FILE
"
||
!
-f
"
$DEST_FILE
"
]]
;
then
echo
"Error: One of the source or destination files is missing!"
exit
1
fi
# Extract users
awk
-F
:
'$3 < 1000'
"
$DEST_FILE
"
>
"
$MERGED_FILE
"
# System users from target
awk
-F
:
'$3 >= 1000'
"
$SOURCE_FILE
"
>>
"
$MERGED_FILE
"
# Normal users from source
# Ensure uniqueness and sort
sort
-t
:
-k1
,1
-u
-o
"
$MERGED_FILE
"
"
$MERGED_FILE
"
done
This diff is collapsed.
Click to expand it.
xx_merge_users.yml
0 → 100644
+
54
−
0
View file @
613abd82
-
name
:
Merge passwd, group, and shadow files from fs5 to target system
hosts
:
localhost
become
:
true
vars
:
root_host
:
fs5
files
:
-
{
name
:
"
passwd"
,
mode
:
"
0644"
}
-
{
name
:
"
group"
,
mode
:
"
0644"
}
-
{
name
:
"
shadow"
,
mode
:
"
0600"
}
local_temp_dir
:
/tmp/user_merge
remote_etc_dir
:
/etc
tasks
:
-
name
:
Ensure local temporary directory exists
file
:
path
:
"
{{
local_temp_dir
}}"
state
:
directory
mode
:
'
0755'
-
name
:
Fetch user-related files from fs5
fetch
:
src
:
"
{{
remote_etc_dir
}}/{{
item.name
}}"
dest
:
"
{{
local_temp_dir
}}/{{
item.name
}}_fs5"
flat
:
true
loop
:
"
{{
files
}}"
delegate_to
:
"
{{
root_host
}}"
vars
:
ansible_ssh_common_args
:
"
-o
StrictHostKeyChecking=no"
-
name
:
Read current target system files
slurp
:
src
:
"
{{
remote_etc_dir
}}/{{
item.name
}}"
register
:
target_files
loop
:
"
{{
files
}}"
-
name
:
Generate user merge script
template
:
src
:
merge_users.sh
dest
:
"
{{
local_temp_dir
}}/merge_users.sh"
mode
:
'
0755'
-
name
:
Execute merge script
command
:
"
{{
local_temp_dir
}}/merge_users.sh
{{
local_temp_dir
}}
{{
remote_etc_dir
}}"
register
:
merge_output
changed_when
:
merge_output.rc ==
0
-
name
:
Replace files if changed
copy
:
src
:
"
{{
local_temp_dir
}}/merged_{{
item.name
}}"
dest
:
"
{{
remote_etc_dir
}}/{{
item.name
}}"
owner
:
root
group
:
root
mode
:
"
{{
item.mode
}}"
backup
:
true
when
:
target_files.results | selectattr('item.name', 'equalto', item.name) | map(attribute='content') | map('b64decode') | first != lookup('file', '{{ local_temp_dir }}/merged_{{ item.name }}')
loop
:
"
{{
files
}}"
-
name
:
Clean up temporary files
file
:
path
:
"
{{
local_temp_dir
}}"
state
:
absent
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment