Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ansible and Scala Projects

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Ansible and Scala Projects

Avatar for Shannon

Shannon

May 30, 2019
Tweet

More Decks by Shannon

Other Decks in Technology

Transcript

  1. What do I want Make everything as simpler as possible,

    but not simpler. Albert Einstein 0pt1mates | @jm2dev 3 / 39
  2. A definition Automated provisioning, also called self-service provision- ing, is

    the ability to deploy an information technology or telecommunications service by using predefined proce- dures that are carried out electronically without requiring human intervention. 0pt1mates | @jm2dev 5 / 39
  3. Ansible ▶ Simple requisites ▶ ssh ▶ python ▶ Simple

    language ▶ yaml 0pt1mates | @jm2dev 7 / 39
  4. Setup ▶ python 3 with virtualenv mkdir proyecto cd proyecto

    python3 -m venv venv 0pt1mates | @jm2dev 8 / 39
  5. Tasks for a dev ▶ software installation ▶ copy files

    ▶ etc Our requirements for a Scala project: ▶ git ▶ openjdk ▶ sbt 0pt1mates | @jm2dev 11 / 39
  6. cat programador/tasks/main.yml --- - name: Update pacman cache become: true

    pacman: update_cache: yes - name: Install packages become: true pacman: name: "{{ item }}" state: present 0pt1mates | @jm2dev 13 / 39
  7. cat programador.yml --- - name: Preparacion proyecto X hosts: local

    connection: local roles: - programador 0pt1mates | @jm2dev 14 / 39
  8. Does it work? cd proyecto source venv/bin/activate pip install -r

    requirements.txt ansible-playbook -i hosts programador.yml 0pt1mates | @jm2dev 15 / 39
  9. Role per project ▶ barebone project ▶ more things to

    automate? 0pt1mates | @jm2dev 16 / 39
  10. Tasks version 2 Let’s clean in it a bit mv

    roles/programador/tasks/main.yml \ roles/programador/tasks/paquetes.yml 0pt1mates | @jm2dev 17 / 39
  11. cat roles/programador/tasks/sbt.yml --- - name: SBT config plugins directory file:

    path: "{{ home_dir }}/.sbt/1.0/plugins" recurse: yes state: directory mode: 0755 - name: SBT Global plugins copy: src: files/plugins.sbt 0pt1mates | @jm2dev 18 / 39
  12. cat roles/programador/files/plugins.sbt addSbtPlugin("org.ensime" % "sbt-ensime" % "2.1.0") addSbtPlugin("io.get-coursier" % "sbt-coursier"

    % "1.1.0-M1 addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1") 0pt1mates | @jm2dev 21 / 39
  13. cat roles/programador/tasks/git.yml --- - name: Git config directory file: path:

    "{{ home_dir }}/.config/git" state: directory mode: 0755 - name: Git setup template: src: templates/git_config.j2 dest: "{{ home_dir }}/.config/git/config" 0pt1mates | @jm2dev 23 / 39
  14. Configuring GIT (II) What are templates? mkdir -p roles/programador/templates touch

    roles/programador/templates/git_config.j2 0pt1mates | @jm2dev 24 / 39
  15. cat roles/programador/templates/gitconfig .j2 [user] name = {{ git_username }} email

    = {{ git_email }} [color] ui = auto [push] default = simple [core] 0pt1mates | @jm2dev 25 / 39
  16. Configuring GIT (IV) And those are … variables? mkdir -p

    roles/programador/vars touch roles/programador/vars/main.yml 0pt1mates | @jm2dev 26 / 39
  17. Developer tasks (II) And the new main.yml version: --- -

    import_tasks: paquetes.yml - import_tasks: git.yml - import_tasks: sbt.yml 0pt1mates | @jm2dev 28 / 39
  18. A database --- - name: Update pacman cache become: true

    pacman: update_cache: yes - name: Install postgresql become: true pacman: name: "{{ item }}" state: present 0pt1mates | @jm2dev 31 / 39
  19. Fatjar ▶ package our service as a fatjar ▶ run

    it locally as a service so we can ▶ run integration/acceptance tests 0pt1mates | @jm2dev 32 / 39
  20. cat roles/fatjar/vars/all service_user: "hello" service_name: "Hello" service_install_dir: "/opt/{{ service_name }}"

    bin_location: "{{ service_install_dir }}/bin/server" 0pt1mates | @jm2dev 34 / 39
  21. cat roles/fatjar/templates/fatjar.service.j2 [Unit] Description={{ service_name }} After=syslog.target [Service] ExecStart={{ bin_location

    }} User={{ service_user }} [Install] WantedBy=multi-user.target 0pt1mates | @jm2dev 35 / 39
  22. cat roles/fatjar/tasks/main.yml - name: Create systemd directory file: path: "{{

    service_install }}" state: directory mode: 0755 - name: Install fatjar service copy: src: "item" dest: "{{ service_install }}" with_items: 0pt1mates | @jm2dev 36 / 39
  23. Playbook --- - name: Preparacion proyecto X hosts: local connection:

    local roles: - programador - proyectoX - fatjar 0pt1mates | @jm2dev 37 / 39