lib/subspace/commands/bootstrap.rb in subspace-2.5.10 vs lib/subspace/commands/bootstrap.rb in subspace-3.0.0.rc1

- old
+ new

@@ -1,7 +1,6 @@ class Subspace::Commands::Bootstrap < Subspace::Commands::Base - PASS_THROUGH_PARAMS = ["private-key"] def initialize(args, options) @host_spec = args.first @options = options @ask_pass = options.password @@ -9,40 +8,36 @@ run end def run # ansible atlanta -m copy -a "src=/etc/hosts dest=/tmp/hosts" - install_python - ensure_ssh_dir + hosts = inventory.find_hosts!(@host_spec) + update_ansible_cfg + hosts.each do |host| + say "Bootstapping #{host.vars["hostname"]}..." + learn_host(host) + install_python(host) + end end private - def ensure_ssh_dir - cmd = ["ansible", - @host_spec, - "-m", - "file", - "-a", - "path=/home/{{ansible_ssh_user}}/.ssh state=directory mode=0700", - "-vvvv" - ] - cmd = cmd | pass_through_params - bootstrap_command cmd + def learn_host(host) + system "ssh-keygen -R #{host.vars["ansible_host"]}" + system "ssh-keyscan -H #{host.vars["ansible_host"]} >> ~/.ssh/known_hosts" end - def install_python - update_ansible_cfg + def install_python(host) cmd = ["ansible", - @host_spec, + host.name, + "--private-key", + "config/subspace/subspace.pem", "-m", "raw", "-a", - "test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)", - "--become", - "-vvvv" + "test -e /usr/bin/python3 || (apt -y update && apt install -y python3)", + "--become" ] - cmd = cmd | pass_through_params bootstrap_command cmd end def bootstrap_command(cmd) if @ask_pass