diff --git a/assets/pages/tips_tricks/tips_n_tricks.md b/assets/pages/tips_tricks/tips_n_tricks.md index c5a7e04..ea15784 100644 --- a/assets/pages/tips_tricks/tips_n_tricks.md +++ b/assets/pages/tips_tricks/tips_n_tricks.md @@ -67,8 +67,8 @@ Example usage: ## 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. -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: -`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'` diff --git a/secdep.py b/secdep.py index ad73591..0d6507c 100755 --- a/secdep.py +++ b/secdep.py @@ -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("ip to connect to", style="bold white") console.print("[bold white]\nIP: %s[/bold white]" % (node.public_ips[0])) - # Here is where we write the node's ip to the file - with open(SECDEP_HOSTS_FILE, "a") as nodesFile: - nodesFile.write(node.public_ips[0]+"\n") + # Here is where we write the node's ip to the file with either :22100 or nothing depending on the deploy parameter console.print("[u]ssh command:[/u]", style="bold white") 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])) + with open(SECDEP_HOSTS_FILE, "a") as nodesFile: + nodesFile.write(node.public_ips[0]+":22100\n") else: 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() return node @@ -1487,7 +1489,7 @@ def node_action(action, provider, awsRegion=None): lines = nodesFile.readlines() with open(SECDEP_HOSTS_FILE, "w") as nodesFile: 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) case _: 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() with open(SECDEP_HOSTS_FILE, "w") as nodesFile: 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) case _: console.print("[u]Invalid[/u] action command", style="bold red")