Derp. Fix missing constant post rename

This commit is contained in:
2023-09-11 00:54:39 +03:00
parent 8824794fc4
commit 5948ad8368
2 changed files with 9 additions and 7 deletions

View File

@@ -67,8 +67,8 @@ Example usage:
## Usage with Ansible 🤖 ## Usage with Ansible 🤖
If you have Ansible installed, you can use the hosts file generated by SecDep to run commands on all of the instances simultaneously. If you have Ansible installed, you can use the hosts file generated by SecDep to run commands on all of the instances simultaneously.
This file is located in the SecDep directory and is being updated every time you create or delete an instance. All instances have a secdep user created and you automatically have an ssh key to use for the connection so as long as you create all instances with or without the `--deploy` flag you can easily use Ansible. That is because this flag calls the hardening script which among the hardening steps changes the default ssh port. If you have Ansible playbooks you wish to run on fresh installations you should create the instances without the `--deploy` flag. This file is located in the SecDep directory and is being updated every time you create or delete an instance. All instances have a secdep user created and you automatically have an ssh key to use for the connection so you can easily use Ansible to run commands to all of them. If you have Ansible playbooks you wish to run on fresh installations you should create the instances without the `--deploy` flag.
Example usage with ansible from the same directory as the hosts file: Example usage with ansible from the same directory as the hosts file:
`ansible all -i hosts --private-key=secdep -u secdep -a 'echo "This text was created by Ansible" > /home/secdep/ansible.txt'` `ansible all -i hosts --private-key=secdep -u secdep -a 'touch ansible.txt'`

View File

@@ -1316,14 +1316,16 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi
console.print("Node is initializing, please wait...", style="bold white") console.print("Node is initializing, please wait...", style="bold white")
console.print("ip to connect to", style="bold white") console.print("ip to connect to", style="bold white")
console.print("[bold white]\nIP: %s[/bold white]" % (node.public_ips[0])) console.print("[bold white]\nIP: %s[/bold white]" % (node.public_ips[0]))
# Here is where we write the node's ip to the file # Here is where we write the node's ip to the file with either :22100 or nothing depending on the deploy parameter
with open(SECDEP_HOSTS_FILE, "a") as nodesFile:
nodesFile.write(node.public_ips[0]+"\n")
console.print("[u]ssh command:[/u]", style="bold white") console.print("[u]ssh command:[/u]", style="bold white")
if args.deploy: if args.deploy:
console.print("[bold white]\nssh -p 22100 -i %s secdep@%s\n[/bold white]" % (SECDEP_SSH_PRIVATE_KEY, node.public_ips[0])) console.print("[bold white]\nssh -p 22100 -i %s secdep@%s\n[/bold white]" % (SECDEP_SSH_PRIVATE_KEY, node.public_ips[0]))
with open(SECDEP_HOSTS_FILE, "a") as nodesFile:
nodesFile.write(node.public_ips[0]+":22100\n")
else: else:
console.print("[bold white]\nssh -i %s secdep@%s\n[/bold white]" % (SECDEP_SSH_PRIVATE_KEY, node.public_ips[0])) console.print("[bold white]\nssh -i %s secdep@%s\n[/bold white]" % (SECDEP_SSH_PRIVATE_KEY, node.public_ips[0]))
with open(SECDEP_HOSTS_FILE, "a") as nodesFile:
nodesFile.write(node.public_ips[0]+"\n")
status.stop() status.stop()
return node return node
@@ -1487,7 +1489,7 @@ def node_action(action, provider, awsRegion=None):
lines = nodesFile.readlines() lines = nodesFile.readlines()
with open(SECDEP_HOSTS_FILE, "w") as nodesFile: with open(SECDEP_HOSTS_FILE, "w") as nodesFile:
for line in lines: for line in lines:
if line.strip("\n") != node.public_ips[0]: if line.strip("\n") != node.public_ips[0] and line.strip("\n") != node.public_ips[0]+":22100":
nodesFile.write(line) nodesFile.write(line)
case _: case _:
console.print("[u]Invalid[/u] action command", style="bold red") console.print("[u]Invalid[/u] action command", style="bold red")
@@ -1535,7 +1537,7 @@ def node_action_all(action, provider, awsRegion=None):
lines = nodesFile.readlines() lines = nodesFile.readlines()
with open(SECDEP_HOSTS_FILE, "w") as nodesFile: with open(SECDEP_HOSTS_FILE, "w") as nodesFile:
for line in lines: for line in lines:
if line.strip("\n") != node.public_ips[0]: if line.strip("\n") != node.public_ips[0] and line.strip("\n") != node.public_ips[0]+":22100":
nodesFile.write(line) nodesFile.write(line)
case _: case _:
console.print("[u]Invalid[/u] action command", style="bold red") console.print("[u]Invalid[/u] action command", style="bold red")