From 942a634a3532f3bc7e89bad78fd48be7e8c2fc5b Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Tue, 3 Mar 2015 14:44:27 -0300 Subject: [PATCH] Remove IP addresses from main configuration file --- README.md | 23 +++++++++++++---------- Rakefile | 15 ++++++++++++++- Vagrantfile | 2 +- ips.development.yaml | 6 ++++++ nodes.yaml | 14 -------------- test/ip_helper.sh | 4 ++-- 6 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 ips.development.yaml diff --git a/README.md b/README.md index 03f4718..0b395c7 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,16 @@ For development ## Configuration parameters -For development, all configuration parameters are defined in the file -`nodes.yaml`. +All configuration parameters are defined in `nodes.yaml`, with exception of IP +addresses, which are defined in different files: -For production, create a new file based on `nodes.yaml`, e.g. -`prod.yaml`. +- for development, the IP addresses of the Vagrant VMs are defined in + ips.development.yaml. -Todos os parâmetros de configuração estão definidos no arquivo nodes.yaml +- for production, you need to create a new file called `ips.production.yaml` + +You will probably not need to change nodes.yaml unless you are developing the +deployment process. ## Deploy @@ -49,13 +52,13 @@ $ rake converge:$server # deploys only $server * TODO: document SSH configuration ```bash -$ rake NODES=prod.yaml # deploys all servers -$ rake nodes NODES=prod.yaml # lists all servers -$ rake converge:$server NODES=prod.yaml # deploys only $server +$ rake SPB_ENV=production # deploys all servers +$ rake nodes SPB_ENV=production # lists all servers +$ rake converge:$server SPB_ENV=production # deploys only $server ``` -You can also do `export NODES=prod.yaml` in your shell and omit the -`NODES=prod.yaml` parameter in the `rake` calls. +You can also do `export SPB_ENV=production` in your shell and omit it in the +`rake` calls. See the output of `rake -T` for other tasks. diff --git a/Rakefile b/Rakefile index 11a0656..97276f4 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,18 @@ require 'chake' +$SPB_ENV = ENV.fetch('SPB_ENV', 'development') +$SPB_IPS = "ips.#{$SPB_ENV}.yaml" + +ips = YAML.load_file($SPB_IPS) +$nodes.each do |node| + node.data['peers'] = ips +end + +task :console do + require 'pry' + binding.pry +end + task :test do sh './test/run_all' end @@ -7,7 +20,7 @@ end task :default => :test file 'ssh_config.erb' -file '.ssh_config' => ['nodes.yaml', 'ssh_config.erb'] do |t| +file '.ssh_config' => ['nodes.yaml', $SPB_IPS,'ssh_config.erb'] do |t| require 'erb' template = ERB.new(File.read('ssh_config.erb')) File.open(t.name, 'w') do |f| diff --git a/Vagrantfile b/Vagrantfile index 80b8126..616bd2e 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -13,7 +13,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.provision 'shell', path: 'utils/proxy.sh', args: [proxy] end - ips = YAML.load_file('nodes.yaml').first[1]['peers'] + ips = YAML.load_file('ips.development.yaml') config.vm.define 'database' do |database| database.vm.network 'private_network', ip: ips['database'] diff --git a/ips.development.yaml b/ips.development.yaml new file mode 100644 index 0000000..8709b17 --- /dev/null +++ b/ips.development.yaml @@ -0,0 +1,6 @@ +integration: 10.10.10.2 +email: 10.10.10.3 +social: 10.10.10.4 +database: 10.10.10.5 +reverseproxy: 10.10.10.6 + diff --git a/nodes.yaml b/nodes.yaml index df9edab..edf6254 100644 --- a/nodes.yaml +++ b/nodes.yaml @@ -15,41 +15,27 @@ vagrant@integration: lists_hostname: listas.softwarepublico.dev lists_admin: paulo@softwarelivre.org relay_hostname: relay.softwarepublico.dev - peers: &PEERS - integration: 10.10.10.2 - email: 10.10.10.3 - social: 10.10.10.4 - database: 10.10.10.5 - reverseproxy: 10.10.10.6 vagrant@email: run_list: - role[server] - role[email_server] config: <<: *CONFIG - peers: - <<: *PEERS vagrant@social: run_list: - role[server] - role[social_server] config: <<: *CONFIG - peers: - <<: *PEERS vagrant@database: run_list: - role[server] - role[database_server] config: <<: *CONFIG - peers: - <<: *PEERS vagrant@reverseproxy: run_list: - role[server] - role[reverse_proxy_server] config: <<: *CONFIG - peers: - <<: *PEERS diff --git a/test/ip_helper.sh b/test/ip_helper.sh index 073b4f8..1ff29b7 100644 --- a/test/ip_helper.sh +++ b/test/ip_helper.sh @@ -4,7 +4,7 @@ # curl http://$reverseproxy # nmap -p 5423 $database # -# Each node in the `peers:` entry in nodes.yaml will have its own variable +# Each entry in ips.${SPB_ENV}.yaml will have its own variable # -eval $(sed -E '/[0-9]{1,3}\./!d; s/^ *//; s/: */=/' ${ROOTDIR:-/vagrant}/nodes.yaml) +eval $(sed -E '/[0-9]{1,3}\./!d; s/^ *//; s/: */=/' ${ROOTDIR:-.}/ips.${SPB_ENV:-development}.yaml) -- libgit2 0.21.2