Skip to content

Initial run of refresh_foreign_tables fails resource because database_geo.yml doesn't exist

When provisioning a new Geo DB secondary, resource bash[refresh foreign table definition] in gitlab-ee::geo-postgresql recipe fails because database_geo.yml hasn't been created yet, it is created later in the geo-secondary recipe.

Log snippet:

  * postgresql_fdw_user_mapping[gitlab_secondary] action create                                                              
    * postgresql_query[create mapping for gitlab_geo at gitlab_secondary] action run (skipped due to not_if)                 
    * postgresql_query[update mapping for gitlab_geo at gitlab_secondary] action run (skipped due to not_if)                 
    * postgresql_query[grant usage on foreign server gitlab_secondary to gitlab_geo] action run (skipped due to not_if)      
     (up to date)                                                                                                            
  * bash[refresh foreign table definition] action run                                                                        
    [execute] Failed to open config/database_geo.yml. Consult the documentation on how to set up GitLab Geo.                               rake aborted!                                                                                                  
              NoMethodError: undefined method `[]' for nil:NilClass                                                                        /opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/geo/database_tasks.rb:175:in `set_db_env'      
              /opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/geo/database_tasks.rb:171:in `ensure in with_geo_db'                 /opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/geo/database_tasks.rb:171:in `with_geo_db'      
              /opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/geo/geo_tasks.rb:59:in `foreign_server_configured?'    
              /opt/gitlab/embedded/service/gitlab-rails/ee/lib/tasks/geo.rake:60:in `block (3 levels) in <top (required)>'
              /opt/gitlab/embedded/bin/bundle:23:in `load'                                                                                 /opt/gitlab/embedded/bin/bundle:23:in `<main>'                                                   
                                                                                                                                           Caused by:                                                                                                     
              SystemExit: Failed to open config/database_geo.yml. Consult the documentation on how to set up GitLab Geo.                   /opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/geo/database_tasks.rb:50:in `abort'                  
              /opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/geo/database_tasks.rb:50:in `abort_if_no_geo_config!'  
              /opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/geo/database_tasks.rb:158:in `with_geo_db'
              /opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/geo/geo_tasks.rb:59:in `foreign_server_configured?'                  /opt/gitlab/embedded/service/gitlab-rails/ee/lib/tasks/geo.rake:60:in `block (3 levels) in <top (required)>'   
              /opt/gitlab/embedded/bin/bundle:23:in `load'                                                                                 /opt/gitlab/embedded/bin/bundle:23:in `<main>'                                                                 
              Tasks: TOP => geo:db:refresh_foreign_tables                                                                                  (See full trace by running task with --trace)                        
    - execute "bash"  "/tmp/chef-script20180410-477-1qp7yvs"                                                                   * execute[reload geo-postgresql] action nothing (skipped due to action :nothing)                       
  * execute[start geo-postgresql again] action nothing (skipped due to action :nothing)