New developer onboarding with Ansible

Your new developer has just finished signing an employment contract and is ready to close 15 tasks a day with burning eyes. There is only one obstacle in his way - a new laptop that has not yet been configured properly. Most often, the process of setting up the environment is described in a document that is issued to a new developer. We did not go very far and also made such a list.





  1. Installing Xcode





  2. Setting up a local git repository





  3. Setting up the environment





  4. Project setup





  5. Reading the documentation





  6. Setting up a task tracker (Jira / Youtrack)





In order not to waste precious developer time on manually setting up a new laptop, we have automated steps 3 and 4, because they are the most labor intensive.





So let's look at setting up the environment first.





Setting up the environment

In our case, setting up the environment consists of several points:





1. Installing brew dependencies





2.    mint





3.    ruby





4.    python





, Ansible. , , , , – playbooks.





, ansible .





:





#!/usr/bin/env bash

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && sudo python get-pip.py

sudo pip install ansible

cd $(dirname $0) && ansible-playbook main.yml
      
      



:





  1. pip





  2. Ansible





  3. main.yml







, main.yml



.





- hosts: localhost
  roles:
	- common_setup
      
      



hosts , , , roles , , .





roles , ,





(meta, tasks vars) main.yml



.





main.yml, roles .





tasks, , . , Ruby rvm.





---

- name: Check if RVM already installed

  stat: path=~/.rvm

  register: rvmdir

  changedwhen: false

- name: Install RVM for a user

  command: bash -c "\curl -sSL https://get.rvm.io | bash -s -- --ignore-dotfiles"

  when: rvmdir.stat.exists == False

- name: Add RVM to profile

  command: bash -c "~/.rvm/bin/rvm get stable --auto-dotfiles"

  when: rvmdir.stat.exists == False

- name: Add RVM to zshrc

  command: bash -c "echo '\n[ -s ${HOME}/.rvm/scripts/rvm ] && source ${HOME}/.rvm/scripts/rvm' >> ~/.zshrc"

  when: rvmdir.stat.exists == False

- name: Install {{ rubyversion }}

  command: bash -c "~/.rvm/bin/rvm install {{ rubyversion }}"

  when: rvmdir.stat.exists == False

- name: Set Ruby Default

  command: bash -c "~/.rvm/bin/rvm --default use {{ rubyversion }}"

  when: rvmdir.stat.exists == False

- name: Install Ruby Gems required for iOS app developement

  gem: name={{ item.name }} version={{ item.version }} state={{ if item.version is defined nil else latest }}

  withitems: "{{ rubygems_packages_to_install }}"

  when: rvmdir.stat.exists == False
      
      



  1. , rvm.





    name



    -





    stat



    - rvm





    register







    changed_when







    , , false. .





  2. rvm.





    name



    -





    command



    -





    when



    -





    rvm, rvmdir



    .





  3. rvm. .





  4. .zshrc . MacOS Catalina , zsh .





  5. Ruby. , vars. main.yml



    :





    rubyversion: ruby-2.6.5







  6. Ruby





  7. , bundler. vars, :





    rubygems_packages_to_install:







      - name: bundler







    version:2.1.4







, .





.





:





#!/usr/bin/ruby

require 'FileUtils'
require 'colorize'

RESOURCES_DIRECTORY = './Scripts/Resources'.freeze
XCODE_DIRECTORY = '~/Library/Developer/Xcode'.freeze

def setup_git_hooks
  puts "Setting up git hooks".blue.bold

  git_hooks_path = '.git/hooks'
  FileUtils.mkdir_p(git_hooks_path)

  Dir["#{RESOURCES_DIRECTORY}/Git hooks/*"].each do |file|
	FileUtils.cp_r(file, "#{git_hooks_path}/#{File.basename(file)}")
  end
end

def setup_file_templates
  puts "\nSetting up file templates".blue.bold

  file_templates_path = File.expand_path("#{XCODE_DIRECTORY}/Templates/File Templates/Tests")
  FileUtils.mkdir_p(file_templates_path)

  Dir["#{RESOURCES_DIRECTORY}/Templates/*.xctemplate"].each do |file|
	FileUtils.cp_r(file, "#{file_templates_path}/#{File.basename(file)}")
  end
end

def setup_xcode_snippets
  puts "\nSetting up xcode snippets".blue.bold

  need_to_reboot_xcode = false

  code_snippets_path = File.expand_path("#{XCODE_DIRECTORY}/UserData/CodeSnippets")
  FileUtils.mkdir_p(code_snippets_path)

  Dir["#{RESOURCES_DIRECTORY}/Snippets/*.codesnippet"].each { |file|
	path = "#{code_snippets_path}/#{File.basename(file)}"
	next if File.file?(path)
	need_to_reboot_xcode = true
	FileUtils.cp_r(file, path)
  }

  return unless need_to_reboot_xcode

  puts 'Quiting Xcode'.blue
  system('killall Xcode')
end

def setup_gems
  puts "\nSetting up gems".blue.bold
  system('bundle install')
end

def setup_mocks
  puts "\nSetting up mocks".blue.bold
  system('cd $(pwd) && swiftymocky generate')
end

def setup_projects
  puts "\nSetting up projects".blue.bold
  system('bundle exec rake update_projects')
end

# Steps

Dir.chdir("#{File.expand_path(File.dirname(__FILE__))}/..")

setup_git_hooks
setup_file_templates
setup_xcode_snippets
setup_gems
setup_mocks
setup_projects
      
      



:





  1. -. , .





  2. .





  3. .





  4. .





  5. .





  6. .





, , . Carthage XcodeGen.





1 , . , , . 





. , -, .








All Articles