Writes the completed template to the designated outfile
(out_file, output)
| 102 | |
| 103 | |
| 104 | def write_template(out_file, output): |
| 105 | """ Writes the completed template to the designated outfile """ |
| 106 | confirmation = input(f"\n{BOLD_RED}Saving inventory to {out_file}, are you sure? y/n{RESET}\n") |
| 107 | if not(confirmation == 'Y' or confirmation == 'y'): |
| 108 | return |
| 109 | try: |
| 110 | with open(out_file, 'w') as file_handler: |
| 111 | file_handler.truncate() # Clear the files before we start |
| 112 | file_handler.write(output) |
| 113 | print(f'{BOLD_RED}Saved{RESET}') |
| 114 | except FileNotFoundError: |
| 115 | print("Unable to write to %s" % str(out_file)) |
| 116 | raise |
| 117 | except OSError as os_error: |
| 118 | print(f"Error opening file: {os_error:}") |
| 119 | raise |
| 120 | |
| 121 | def create_hosts_template(out_file, all_hosts): |
| 122 | """ Sets all the neccesary variables to print the jinja2 template """ |
no outgoing calls
no test coverage detected