automate all the things - sebastian feldmann · ansible modules • package management (apt,...

120
Automate all the things Sebastian Feldmann

Upload: others

Post on 22-Jul-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Automate all the things

Sebastian Feldmann

Page 2: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

"Automate until the job is boring as hell"

Page 3: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

System Configuration

Page 4: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Software packaging

Page 5: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Software deployment

Page 6: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Combining all to work seamlessly together

Page 7: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

System Configuration

Page 8: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

“App deployment, configuration management and orchestrationall from one system. Powerful automation that you can learn quickly.“

Page 9: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

About Ansible

• Written in Python

• Using SSH

• No agents

• YAML

Page 10: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ansible Modules• Package management (apt, yum…)

• Command execution (command, shell)

• Service management (start, stop…)

• File handling (copy, template…)

• SCM (git, Bazzar, Subversion)

Page 11: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Inventory

Page 12: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Roles

Page 13: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Playbook

Page 14: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

System configuration with Ansible

Page 15: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Inventory

ops/+-inv/+-integration/+-local/+-production/

good practice inventory setup

Page 16: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Inventory

[webserver]192.168.1.111

[dbserver]192.168.1.222192.168.1.223

ops/inv/integration/hosts

Page 17: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Playbook

-hosts:webserverroles:-apache

ops/install.webserver.yml

Page 18: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Role

ops/+-roles/|+-apache/|+-files/|+-handlers/|+-tasks/|+-templates/+-install.webserver.yml

good practice role setup

Page 19: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

-name:installapacheaction:aptpkg=apache2state=presentforce=yes

-name:copympmpreforkconfcopy:dest=/etc/apache2/mods-available/mpm_prefork.confsrc=mpm_prefork.confnotify:restartapache

ops/roles/apache/tasks/main.yml

Page 20: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

-name:installapacheaction:aptpkg=apache2state=presentforce=yes

-name:copympmpreforkconfcopy:dest=/etc/apache2/mods-available/mpm_prefork.confsrc=mpm_prefork.confnotify:restartapache

ops/roles/apache/tasks/main.yml

Page 21: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

-name:installapacheaction:aptpkg=apache2state=presentforce=yes

-name:copympmpreforkconfcopy:dest=/etc/apache2/mods-available/mpm_prefork.confsrc=mpm_prefork.confnotify:restartapache

ops/roles/apache/tasks/main.yml

Page 22: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

-name:installapacheaction:aptpkg=apache2state=presentforce=yes

-name:copympmpreforkconfcopy:dest=/etc/apache2/mods-available/mpm_prefork.confsrc=mpm_prefork.confnotify:restartapache

ops/roles/apache/tasks/main.yml

Page 23: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Handler

-name:restartapacheaction:servicename=apache2state=restarted

ops/roles/apache/handlers/main.yml

Page 24: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Handler

-name:restartapacheaction:servicename=apache2state=restarted

ops/roles/apache/handlers/main.yml

Page 25: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Recap

• Create inventories

• Install playbook

• Apache role

• Install tasks / handlers

Page 26: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Execute Ansible

$ansible-playbook-iinv/integration/hostsinstall.webserver.yml

execution example

Page 27: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Execute Ansible

$ansible-playbook-iinv/integration/hostsinstall.webserver.yml

execution example

Page 28: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Execute Ansible

$ansible-playbook-iinv/integration/hostsinstall.webserver.yml

execution example

Page 29: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Execute Ansible

$ansible-playbook-iinv/integration/hostsinstall.webserver.yml

execution example

Page 30: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

PLAYBOOK:install.webserver.yml*******************************************1playsinansible/install.webserver.yml

PLAY[webserver]***************************************************************

TASK[apache:installapache]***************************************************************ok:[192.168.1.111]

TASK[apache-c24:copympmpreforkconf]*********************************************ok:[192.168.1.111]NOTIFIEDHANDLERrestartapache

PLAYRECAP****************************************************192.168.1.111:ok=2changed=2unreachable=0failed=0

Finished:SUCCESS

Page 31: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

PLAYBOOK:install.webserver.yml*******************************************1playsinansible/install.webserver.yml

PLAY[webserver]***************************************************************

TASK[apache:installapache]***************************************************************ok:[192.168.1.111]

TASK[apache-c24:copympmpreforkconf]*********************************************ok:[192.168.1.111]NOTIFIEDHANDLERrestartapache

PLAYRECAP****************************************************192.168.1.111:ok=2changed=0unreachable=0failed=0

Finished:SUCCESS

Page 32: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Execute Ansible

$ansible-playbook-iinv/integration/hosts--checkinstall.webserver.yml

dry run with --check

$ansible-playbook-iinv/integration/hosts--limit192.168.1.111install.webserver.yml

restrict execution with --limit

Page 33: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)
Page 34: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Software Packaging

Page 35: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

"Ant can be used to pilot any type of process which can be described in terms of targets and tasks"

Page 36: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ant

• Written in Java

• XML configuration

• Targets (tasks)

• Bundled with Java

Page 37: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Software packaging with Ant

Page 38: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ant Configuration

build.xml

<?xmlversion="1.0"encoding="UTF-8"?><projectname="projectx"default="build"><targetname="build"depends="target1,target2,target3"/><targetname="target1">...</target><targetname="target2">...</target>...</project>

Page 39: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ant Configuration

build.xml

<?xmlversion="1.0"encoding="UTF-8"?><projectname="projectx"default="build"><targetname="build"depends="target1,target2,target3"/><targetname="target1">...</target><targetname="target2">...</target>...</project>

Page 40: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ant Configuration

build.xml

<?xmlversion="1.0"encoding="UTF-8"?><projectname="projectx"default="build"><targetname="build"depends="target1,target2,target3"/><targetname="target1">...</target><targetname="target2">...</target>...</project>

Page 41: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ant Configuration

build.xml

<?xmlversion="1.0"encoding="UTF-8"?><projectname="projectx"default="build"><targetname="build"depends="target1,target2,target3"/><targetname="target1">...</target><targetname="target2">...</target>...</project>

Page 42: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Composer

<targetname="composer-install"><execexecutable="composer"failonerror="true"><argvalue="install"/><argvalue="--no-interaction"/></exec></target>

build.xml

Page 43: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Composer

<targetname="composer-install"><execexecutable="composer"failonerror="true"><argvalue="install"/><argvalue="--no-interaction"/></exec></target>

build.xml

Page 44: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Composer

<targetname="composer-install"><execexecutable="composer"failonerror="true"><argvalue="install"/><argvalue="--no-interaction"/></exec></target>

build.xml

Page 45: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Composer

<targetname="composer-install"><execexecutable="composer"failonerror="true"><argvalue="install"/><argvalue="--no-interaction"/></exec></target>

build.xml

Page 46: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Composer

<targetname="composer-install"><execexecutable="composer"failonerror="true"><argvalue="install"/><argvalue="--no-interaction"/></exec></target>

build.xml

Page 47: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

PHPUnit

<targetname="phpunit"description="Rununittests"><execexecutable="phpunit"failonerror="true"></exec></target>

build.xml

Page 48: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

PHPUnit

<targetname="phpunit"description="Rununittests"><execexecutable="phpunit"failonerror="true"></exec></target>

build.xml

Page 49: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

PHPUnit

<targetname="phpunit"description="Rununittests"><execexecutable="phpunit"failonerror="true"></exec></target>

build.xml

Page 50: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

PHPUnit

<targetname="phpunit"description="Rununittests"><execexecutable="phpunit"failonerror="true"></exec></target>

build.xml

Page 51: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ant Tasks

• Minify Assets

• Cache warmup (Templates, DIContainer…)

• …

Page 52: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ant Execution

$ant

execute default target

$antphpunit

execute specific target

Page 53: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)
Page 54: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Software Deployment

Page 55: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Software deployment with Ansible

Page 56: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Software Deployment

• Copy app to server

• Activate deployed app

• Allow quick rollbacks

Page 57: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Half Way There

• Enhance the inventory

• New playbook

• New role

Page 58: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Inventory

ops/+-inv/+-integration/+-group_vars/+-host_vars/

add variables

Page 59: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Variables

system:environment:integration

projectx:domain:www.projectx.int

ops/inv/integration/group_vars/webserver

Page 60: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Playbook

- hosts:webserverroles:-projectx

ops/deploy.projectx.yml

Page 61: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Role

ops/+-roles/|+-projectx/|+-files/|+-handler/|+-tasks/|+-templates/+-deploy.projectx.yml

best practice role setup

Page 62: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks#createthedirectoryforthecurrentappversion-name:Createversiondirectoryfile:path=/var/www/projectx/{{version}}state=directory

#copythepreparedapptoyourwebservers-name:Copyfilestoserversynchronize:src={{app}}dest=/var/www/projectx/{{version}}perms=yesrecursive=yesdelete=yesowner=nogroup=no

ops/roles/projectx/main.yml

Page 63: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks#createthedirectoryforthecurrentappversion-name:Createversiondirectoryfile:path=/var/www/projectx/{{version}}state=directory

#copythepreparedapptoyourwebservers-name:Copyfilestoserversynchronize:src={{app}}dest=/var/www/projectx/{{version}}perms=yesrecursive=yesdelete=yesowner=nogroup=no

ops/roles/projectx/main.yml

Page 64: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks#createthedirectoryforthecurrentappversion-name:Createversiondirectoryfile:path=/var/www/projectx/{{version}}state=directory

#copythepreparedapptoyourwebservers-name:Copyfilestoserversynchronize:src={{app}}dest=/var/www/projectx/{{version}}perms=yesrecursive=yesdelete=yesowner=nogroup=no

ops/roles/projectx/main.yml

Page 65: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks#createthedirectoryforthecurrentappversion-name:Createversiondirectoryfile:path=/var/www/projectx/{{version}}state=directory

#copythepreparedapptoyourwebservers-name:Copyfilestoserversynchronize:src={{app}}dest=/var/www/projectx/{{version}}perms=yesrecursive=yesdelete=yesowner=nogroup=no

ops/roles/projectx/main.yml

Page 66: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

#deploythevhostconfigurationforourproject-name:Deployvhostconfigurationaction:templatesrc=projectx.confdest=/etc/apache2/sites-available/projectx.confnotify:restartapachetags:rollback

ops/roles/projectx/main.yml

Page 67: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

#deploythevhostconfigurationforourproject-name:Deployvhostconfigurationaction:templatesrc=projectx.confdest=/etc/apache2/sites-available/projectx.confnotify:restartapachetags:rollback

ops/roles/projectx/main.yml

Page 68: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

#deploythevhostconfigurationforourproject-name:Deployvhostconfigurationaction:templatesrc=projectx.confdest=/etc/apache2/sites-available/projectx.confnotify:restartapachetags:rollback

ops/roles/projectx/main.yml

Page 69: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

#deploythevhostconfigurationforourproject-name:Deployvhostconfigurationaction:templatesrc=projectx.confdest=/etc/apache2/sites-available/projectx.confnotify:restartapachetags:rollback

ops/roles/projectx/main.yml

Page 70: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

#deploythevhostconfigurationforourproject-name:Deployvhostconfigurationaction:templatesrc=projectx.confdest=/etc/apache2/sites-available/projectx.confnotify:restartapachetags:rollback

ops/roles/projectx/main.yml

Page 71: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

#createasymlinktoactivatethevhost#couldbedonewith"command:a2ensiteprojectx.conf"#butthiswouldalwaystriggeranapacherestart#evenifnothingchanges-name:Activatevhostconfigurationfile:dest=/etc/apache2/sites-enabled/010-projectx.confsrc=/etc/apache2/sites-available/projectx.confstate=linknotify:restartapache

ops/roles/projectx/tasks/main.yml

Page 72: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

#createasymlinktoactivatethevhost#couldbedonewith"command:a2ensiteprojectx.conf"#butthiswouldalwaystriggeranapacherestart#evenifnothingchanges-name:Activatevhostconfigurationfile:dest=/etc/apache2/sites-enabled/010-projectx.confsrc=/etc/apache2/sites-available/projectx.confstate=linknotify:restartapache

ops/roles/projectx/tasks/main.yml

Page 73: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

#createasymlinktoactivatethevhost#couldbedonewith"command:a2ensiteprojectx.conf"#butthiswouldalwaystriggeranapacherestart#evenifnothingchanges-name:Activatevhostconfigurationfile:dest=/etc/apache2/sites-enabled/010-projectx.confsrc=/etc/apache2/sites-available/projectx.confstate=linknotify:restartapache

ops/roles/projectx/tasks/main.yml

Page 74: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

#createasymlinktoactivatethevhost#couldbedonewith"command:a2ensiteprojectx.conf"#butthiswouldalwaystriggeranapacherestart#evenifnothingchanges-name:Activatevhostconfigurationfile:dest=/etc/apache2/sites-enabled/010-projectx.confsrc=/etc/apache2/sites-available/projectx.confstate=linknotify:restartapache

ops/roles/projectx/tasks/main.yml

Page 75: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

#createasymlinktoactivatethevhost#couldbedonewith"command:a2ensiteprojectx.conf"#butthiswouldalwaystriggeranapacherestart#evenifnothingchanges-name:Activatevhostconfigurationfile:dest=/etc/apache2/sites-enabled/010-projectx.confsrc=/etc/apache2/sites-available/projectx.confstate=linknotify:restartapache

ops/roles/projectx/tasks/main.yml

Page 76: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Template

<VirtualHost*:80>ServerName{{projectx.domain}}DocumentRoot/var/www/projectx/{{version}}/htdocs

setenvAPP.ENVIRONMENT{{system.environment}}

<Directory/var/www/projectx/{{version}}/htdocs>AllowOverrideAllRequireallgranted</Directory></VirtualHost>

ops/roles/projectx/templates/projectx.conf

Page 77: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Variables

system:environment:integration

projectx:domain:www.projectx.int

ops/inv/integration/group_vars/webserver

Page 78: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Template

<VirtualHost*:80>ServerName{{projectx.domain}}DocumentRoot/var/www/projectx/{{version}}/htdocs

setenvAPP.ENVIRONMENT{{system.environment}}

<Directory/var/www/projectx/{{version}}/htdocs>AllowOverrideAllRequireallgranted</Directory></VirtualHost>

ops/roles/projectx/templates/projectx.conf

Page 79: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Recap

• Inventory variables

• Deploy playbook

• Project role

• Deployment tasks

Page 80: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Execute Ansible

$ansible-playbook-iinv/integration/hosts--extra-vars"version=1.0.1app=/some/local/dir/app/"deploy.projectx.yml

deployment execution

Page 81: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Execute Ansible

$ansible-playbook-iinv/integration/hosts--extra-vars"version=1.0.1app=/some/local/dir/app/"deploy.projectx.yml

deployment execution

Page 82: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Execute Ansible

$ansible-playbook-iinv/integration/hosts--extra-vars"version=1.0.1app=/some/local/dir/app/"deploy.projectx.yml

deployment execution

Page 83: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Execute Ansible

$ansible-playbook-iinv/integration/hosts--extra-vars"version=1.0.1app=/some/local/dir/app/"deploy.projectx.yml

deployment execution

Page 84: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Execute Ansible

$ansible-playbook-iinv/integration/hosts--extra-vars"version=1.0.1app=/some/local/dir/app/"deploy.projectx.yml

deployment execution

Page 85: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Execute Ansible

$ansible-playbook-iinv/integration/hosts--extra-vars"version=1.0.1app=/some/local/dir/app/"deploy.projectx.yml

deployment execution

Page 86: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Tasks

#deploythevhostconfigurationforourproject-name:Deployvhostconfigurationaction:templatesrc=projectx.confdest=/etc/apache2/sites-available/projectx.confnotify:restartapachetags:rollback

ops/roles/projectx/main.yml

Page 87: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Template

<VirtualHost*:80>ServerName{{projectx.domain}}DocumentRoot/var/www/projectx/{{version}}/htdocs

setenvAPP.ENVIRONMENT{{system.environment}}

<Directory/var/www/projectx/{{version}}/htdocs>AllowOverrideAllRequireallgranted</Directory></VirtualHost>

ops/roles/projectx/templates/projectx.conf

Page 88: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Rollback

$ansible-playbook-iinv/integration/hosts--extra-vars"version=1.0.0"--tagsrollbackdeploy.projectx.yml

rollback execution

Page 89: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)
Page 90: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

System Config

• Clone repository

• Execute Ansible

Page 91: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Deployment

• Tag version

• Checkout version

• Execute Ant

• Execute Ansible

Page 92: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Not boring!

Page 93: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

NOT BAD

Page 94: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

But I only want to click a button

Page 95: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

And everything should work

Page 96: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

“Build great things at any scale“

Page 97: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Jenkins

• Written in Java

• Build server

• Projects / Jobs

• Jetty (build in webserver)

Page 98: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ansible Plugin

Page 99: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

System configuration with Ansible and Jenkins

Page 100: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

System Management

Page 101: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

SCM Config

use some SCM to manage your Ansible project

Page 102: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Parameter Setup

Page 103: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ansible Plugin Config

parameter usage

Page 104: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Job Execution

Page 105: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

System Configuration

• Push code to git repository

• Push a button

Page 106: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Software packaging and deployment with Ant, Ansible and Jenkins

Page 107: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Software Deployment

Page 108: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Parameter Setup

Page 109: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

SCM Config

configure projectx SCM

Page 110: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ant

Ant support out of the box

Page 111: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ansible Plugin Config

setup ansible playbook and inventory

Page 112: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Ansible Extra Variables

setup version and application directory

Page 113: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Job Execution

Page 114: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

App Deployment

• Tag version in git repository

• Push button

Page 115: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Recap

• System Management Build

• Software Deployment Build

• Execute everything with a single click

Page 116: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Is it getting boring yet?

Page 117: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

At least a little right ;)

Page 118: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)
Page 119: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)
Page 120: Automate all the things - Sebastian Feldmann · Ansible Modules • Package management (apt, yum…) • Command execution (command, shell) • Service management (start, stop…)

Sebastian Feldmann

@movetodevnull

https://phpbu.de

sebastianfeldmann