title: Ruby On Rails: How to write yml configurations in a file when deploying with Capistrano 3?
body: <p>My problem is really simple but I just can't find an answer on google. </p>
  
  <p>I would like to insert a yml configuration into a remote file on my server through a Capistrano task. </p>
  
  <p>While it was really easy with Capistrano 2 and the "put" command, I just can't find the right way to do it with Capistrano 3. </p>
  
  <p>For instance, here is my yml configuration:</p>
  
  <pre><code>    set(:database_username, "db_user")
  
      ask(:database_password, "Database Password: ")
  
      db_config = &lt;&lt;-EOF
        base: &amp;base
          adapter: postgresql
          encoding: unicode
          reconnect: false
          pool: 10
          username: #{fetch(:database_username)}
          password: #{fetch(:database_password)}
  
        staging:
          database: #{fetch(:application)}_staging
          &lt;&lt;: *base
  
        production:
          database: #{fetch(:application)}_production
          &lt;&lt;: *base
      EOF
  </code></pre>
  
  <p>I'd like to insert my "db_config" variable in the database.yml file. Using Capistrano 2 I would do so like this:</p>
  
  <pre><code>put db_config, "#{shared_path}/config/database.yml"
  </code></pre>
  
  <p>But with Capistrano 3 it no longer works. 
  I tried something like this: </p>
  
  <pre><code>execute "echo '#{db_config}' &gt; #{shared_path}/config/database.yml"
  </code></pre>
  
  <p>But end of lines are not kept, they are replaced by ";" because of the 'echo' command. </p>
  
  <p>Does anyone have ever performed something like this with Capistrano 3? </p>
  
  <p>Otherwise, I will just go along with a "database.yml.example" and modify it directly after deployment.</p>
  
  <p>Thanks!</p>
  
  <p>[UPDATE] here is my whole Capistrano 3 task code: </p>
  
  <pre><code>namespace :db do
    desc "Create database yaml in shared path"
    task :configure do
      on roles(:db) do
        if capture("cat #{shared_path}/config/database.yml").length &gt; 0
          puts "### INFO: Database.yml already exists"
        else
          set(:database_username, "db_user")    
          ask(:database_password, "Database Password: ")
  
          db_config = &lt;&lt;-EOF
            base: &amp;base
              adapter: postgresql
              encoding: unicode
              reconnect: false
              pool: 10
              username: #{fetch(:database_username)}
              password: #{fetch(:database_password)}
  
            staging:
              database: #{fetch(:application)}_staging
              &lt;&lt;: *base
  
            production:
              database: #{fetch(:application)}_production
              &lt;&lt;: *base
          EOF
  
          execute "mkdir -p #{shared_path}/config"
          execute "touch #{shared_path}/config/database.yml"
  
          # Everything works so far. This is the buggy part:
          #execute "echo '#{db_config}' &gt; #{shared_path}/config/database.yml"
          execute "cat '#{db_config}' &gt; #{shared_path}/config/database.yml"
        end
      end
    end
  end
  </code></pre>