Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Pito Salas
    @pitosalas
    Thanks for setting this up! And @pblesi thanks for the answers to my github issues. I will follow up here!
    Pito Salas
    @pitosalas
    Following up on @pblesi comments in the issue...
    "Is the intent to have the process run in parallel during the life of the runbook or to have the runbook start the process so it executes indefinitely? In the former case, using tmux_command is the preferred way to execute processes in parallel with the execution of the runbook. In the latter case, I would recommend using some sort of process manager to ensure your process continues to run and then to interact with your process manager to start or stop the process."
    I'm new to devops and automation this way... what's the best practice: If the runback keeps running then I can see what my long running command is doing... but if the server crashes it won't auto restart...
    Is it abnormal to keep runbook open while my service/server runs? I think probably that would not be the way to go.
    Pito Salas
    @pitosalas
    You mention using some sort of process manager. like?
    Patrick Blesi
    @pblesi
    Yeah, agreed that it would be abnormal to keep runbook open while your service runs. So using a process manager is likely the better way to go. At Braintree, we use http://godrb.com/, though this is mostly for legacy reasons. I don't know that I would recommend it if choosing a process manager today. If you are in a unix environment, systemd may be a good option. I haven't personally set up a service to be managed by systemd, but that is the linux/unix go-to. This seems like a decent example resource, but there are probably better ones out there: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-unit_files
    Pito Salas
    @pitosalas
    It seems that where I am deploying, digital ocean, systemctl is the goto so that's what I am settingup.
    Another little question: lets say I have multiple 'tasks' I want to do, e.g. install software; start service; stop service; update software etc. I would have liked to be able to do 'runbook exec servercommands start' or something. So kind of like make whatnot to have a goal as a single parameter to the runbook.
    Pito Salas
    @pitosalas
    What's the way to conditionally execute something, e.g. if this directory does not exist then git clone to create it.
    Pito Salas
    @pitosalas
    this short gitbook "hangs"... why?
    #!/usr/bin/env ruby
    require "runbook"
    require_relative "rbookenv.rb"
    
    runbook = Runbook.book "Setup Primary" do
      server "rails@" + PRIMARY_SERVER_IP
      section "check whether everything is ok" do
        step "clone if needed" do
          capture %q(cd soa_demo; ls; grep "gemfile"), into: :foo, raw: true
          puts @foo
          # command "git clone https://github.com/pitosalas/soa_demo.git"
          #assert %q(cd soa_demo; ls; grep "gemfile")
        end
      end
    end
    if __FILE__ == $0
      Runbook::Runner.new(runbook).run, start_at: 1
    else
      runbook
    end
    (i meant runbook obviously)
    Ok I know why. should have a pipe instead of a semicolon before grep
    Patrick Blesi
    @pblesi
    @pitosalas I really like the idea of a single runbook where you can pass separate commands like runbook exec servercommands start I'll think about the cleanest way to implement something like this.

    For puts @foo, @foo will not be defined in that scope. You will need to do something like:

    ruby_command { puts @foo }

    This is because the capture command simply states that a capture will be executed, but it does not actually execute the capture. Here's some more details: https://github.com/braintree/runbook#why-is-my-variablemethod-not-set

    Patrick Blesi
    @pblesi
    :point_up: February 12, 2020 6:49 AM Probably the cleanest way to do this at the moment is within the shell command itself, so something like:
    if ! [ -d /home ]; then echo hi; fi
    I would like to add a test runbook statement to do this more natively, but it is not yet implemented
    Pito Salas
    @pitosalas
    Hi again, back after a brief hiatus...
    Why is this command giving an error even though it works ok on the command line: command 'curl http://www.rabbitmq.com/rabbitmq-signing-key-public.asc | sudo apt-key add'
    Patrick Blesi
    @pblesi
    Hi PIto!
    I would be curious to see the error. I would potentially try using raw: true again. Additionally commands are non-interactive, so I would use the user setter to set the user to root such as in this example: https://github.com/braintree/runbook#runbook-anatomy. If you didn't want to execute the curl as root, then you could capture the key using capture and then execute a command like command %Q{echo "#{rabbitmq_key}" | apt-key add}
    Pito Salas
    @pitosalas
    Hi Patrick... I am trying to make a runbook with two parts. The same server, the first part is using root and the second part in another account.
    /usr/bin/env ruby
    
    require "runbook"
    require_relative "rbook_env.rb"
    
    Runbook.book "Setup Worker" do
      description <<-HERE
      Assumes that an account called worker will log in 
      HERE
    
      server WORKER_SERVER_IP
      user "root"
    
      section "Add Ruby" do
        step "Install Ruby" do
          command "apt update"
          command "apt install -y ruby-full"
        end
      end
    
      section "install bundler" do
        user "worker"
        step "install bundler" do
          command "gem install bundler"
          command "cd soa_demo; bundle", raw: true
        end
      end
    
    
    
      section "Check whether everything is ok" do
        step "Clone the soa_demo repo if it is needed" do
          capture "ls", into: :res, raw: true
          ruby_command do
            if !@res.include? "soa_demo"
              command "git clone https://github.com/pitosalas/soa_demo.git"
            else
              puts "[git clone already exists]"
            end
          end
        end
      end
    
      section "Add soa-worker systemctl file if needed" do
        # file is at /etc/systemd/system/soa-primary.service
      end
    
      section "Add Papertrail" do
        step "install papertrail cli" do
          # [sudo] gem install papertrail
        end
      end
    
    end
    When the "user worker" command is parsed, I get an error saying that I can't' change to "worker" using sudo. Huh? What's the right way to structure this? Thanks!
    @pblesi do you get alerts from here?
    Patrick Blesi
    @pblesi
    @pitosalas I do get alerts. Could you post the exact error? I have a hunch as to what the issue is, but it would be helpful to see the exact error message
    Pito Salas
    @pitosalas
    It's a long stack trace which I can publish... but until then
    /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.16.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing on host 167.71.163.241: Authentication failed for user pitosalas@167.71.163.241 (SSHKit::Runner::ExecuteError)
    in the meanwhile I've tried some experiments trying to understand how user x works. I found that putting the server and user commands inside the section that installs ruby seems to go better...
    Patrick Blesi
    @pblesi
    Yeah, I made a design choice such that if any of the setters are specified at a given level (step, section, etc.) then it does not merge the setters with upper levels. The thought process being it would be easier to reason about behavior if you see the full set of modifiers in the same place. So by only specifying the user, you would be targeting the default server, which should be localhost.
    Pito Salas
    @pitosalas
    Ok... I get that. Now when I put server <ip> (without user@) it fails because it tries to log into <ip> using my local username. I assume that's as designed too.
    Also when I say server root@<ip> and then later say user "worker" that fails because it tries to "sudo worker" which is not legit. That's weird.
    Pito Salas
    @pitosalas
    UI feedback: it seems redundant that I am asked whether I want to continue a step, and once I press c I still have to press enter.
    Pito Salas
    @pitosalas
    This line in the doc seems to have more than one syntax error: upload my_secrets.yml, to: secrets.yml, ssh_config: {servers: ["host1.prod"]}, options: {log_percent: 10}
    Patrick Blesi
    @pblesi
    What is the syntax error?
    I'd appreciate a pull request if you're willing
    Pito Salas
    @pitosalas
    I would be willing but I've not even tried to understand the source ...
    For one my_secrets.yml should be quoted. But I also thing there's something wrong with the ssh_config.
    Patrick Blesi
    @pblesi
    Right. It looks like my_secrets.yml and secrets.yml should be quoted. It's possible that all arguments to upload might need to be wrapped in quotes as well. In terms of a PR I meant simply to update the README.md
    Patrick Blesi
    @pblesi
    ^ not quotes but parenthesis rather
    Pito Salas
    @pitosalas
    sure I am glad to do that.
    I am not clear on how I can set environment variables for when the next execute command happens. I tried many variations of the env() method and can't get it to work. Tips?
    Patrick Blesi
    @pblesi
    It's surprising that the env setter doesn't work: https://github.com/braintree/runbook#setters This isn't for a raw: true command is it? env won't apply in this case. Sometimes the enclosing {} are required around the arguments to env: https://github.com/braintree/runbook#specifying-env-values
    Pito Salas
    @pitosalas
    On the plane I was looking at the Runbook source to see if I could help with it. That's some serious meta programming your doing there! I didn't figure out how env works. But here are some questions (according to your understanding)
    1. Can an env take a hash with more than one enviornment variable, e.g. env ({work_ip: "1.2.3.4", main_ip: "2.3.4.5"})
    2. Does an env need to be at the book, section or step level or can it be on any of them?
    3. My intent is that the stated environment variables are defined (exported?) when a subsequent "command" line is encountered. Is that correct?
    4. Does the env get sent directly to sshkit or does runbook handle it?
    5. My intent is that with the above example, command "ls" becomes the moral equivalent of command "WORK_IP=1.2.3.4, MAIN_IP=2.3.4.5 ls". Am I right?
    Patrick Blesi
    @pblesi
    Yeah, the setter code is particularly metaprogramming heavy! env can take multiple environment variables as in your example. The env can be defined at any level, but as I mentioned before if any of the setters are set at a lower level, then all setters at a higher level are ignored. Here is the implementation of that: https://github.com/braintree/runbook/blob/799c2e2869423ed1af3d56e6c2ba5459ac1143a9/lib/runbook/helpers/ssh_kit_helper.rb#L24-L30 . The env gets passed directly to sshkit. the env you set gets passed to the with method in sshkit: https://github.com/capistrano/sshkit#example. Your example should be correct with the exception of the comma between the envs so command "WORK_IP=1.2.3.4 MAIN_IP=2.3.4.5 ls"
    Matt Menzenski
    @menzenski
    Hi! Are there any best practices/recommendations around configuration in the Runbookfile? I'm specifically interested in defining a mongodb connection for multiple environments and don't want to reinvent that wheel if there's a good pattern to follow