kolla-ansible/kolla/cmd/mergepwd.py
Vladislav Belogrudov 0ea98608e5 Sometimes merging of passwords.yml gives json
Dumping of password dictionary can look quite different depending
on passwords structure. To always get yaml we need to use block
style for dump(), see
    http://pyyaml.org/wiki/PyYAMLDocumentation#Dictionarieswithoutnestedcollectionsarenotdumpedcorrectly

Change-Id: Ideee1aefedbba35480947956821341c6ef75088e
Closes-Bug: #1647308
2016-12-05 13:17:54 +03:00

40 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python
# 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.
import argparse
import yaml
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--old", help="old password file", required=True)
parser.add_argument("--new", help="new password file", required=True)
parser.add_argument("--final", help="merged password file", required=True)
args = parser.parse_args()
with open(args.old, "r") as old_file:
old_passwords = yaml.safe_load(old_file)
with open(args.new, "r") as new_file:
new_passwords = yaml.safe_load(new_file)
new_passwords.update(old_passwords)
with open(args.final, "w") as destination:
yaml.dump(new_passwords, destination, default_flow_style=False)
if __name__ == '__main__':
main()