-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07f2b24
commit 6bede70
Showing
6 changed files
with
187 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
|
||
- name: Add data to a file | ||
hosts: localhost | ||
tasks: | ||
- name: Show content to update | ||
debug: | ||
msg: | ||
- "Data: {{ data }}" | ||
- "Path: {{ path }}" | ||
|
||
- name: Create file if it doesn't exist | ||
ansible.builtin.file: | ||
path: "{{ path }}" | ||
state: touch | ||
|
||
- name: Ensure data entry is present (lineinfile) | ||
ansible.builtin.lineinfile: | ||
path: "{{ path }}" | ||
line: "{{ data }}" | ||
state: present |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/bin/bash | ||
# Copyright (C) SchedMD LLC. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
update_file() { | ||
local path="$1" | ||
local data="$2" | ||
|
||
if [[ -z "$path" || -z "$data" ]]; then | ||
echo "Error: func_update_fstab requires two arguments: path and data" | ||
return 1 | ||
fi | ||
|
||
# Create JSON data | ||
local json_data='{"path": "'"${path}"'", "data": "'"${data}"'"}' | ||
|
||
# Run Ansible playbook and use network_storage.yml. | ||
ansible-playbook network_storage.yml -e "$json_data" | ||
local exit_status=$? | ||
if [[ $exit_status -ne 0 ]]; then | ||
echo "ansible playbook failed with exit code $exit_status" | ||
return $exit_status | ||
fi | ||
|
||
echo "ansible updated file successfully" | ||
} | ||
|
||
run_cmd() { | ||
local command="$1" | ||
shift # Remove the command itself from the arguments | ||
|
||
if [[ -z "$command" ]]; then | ||
echo "Error: run_cmd requires at least one argument (the command to run)" | ||
return 1 | ||
fi | ||
|
||
echo "Running command: $command $@" | ||
"$command" "$@" # Execute the command with remaining arguments | ||
local exit_status=$? | ||
if [[ $exit_status -ne 0 ]]; then | ||
echo "Command failed with exit code $exit_status" | ||
return $exit_status # Propagate error | ||
fi | ||
} | ||
|
||
if [[ "$1" == "update_file" ]]; then | ||
shift | ||
update_file "$@" | ||
elif [[ "$1" == "run_cmd" ]]; then | ||
shift | ||
run_cmd "$@" | ||
else | ||
echo "Usage: $0 {update_file|run_cmd} [arguments...]" | ||
echo " update_file: file_name line_to_add" | ||
echo " run_cmd: command [arg1] [arg2] ..." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters