Skip to content

Commit

Permalink
Ansible new syntax for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic-gasc committed May 2, 2018
1 parent 3961a35 commit 4db62f5
Show file tree
Hide file tree
Showing 17 changed files with 472 additions and 315 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -6,3 +6,5 @@ _book/
node_modules/


*.retry
package-lock.json
26 changes: 21 additions & 5 deletions step-00/setup.yml
@@ -1,3 +1,4 @@
---
- hosts: all
become: yes
become_user: root
Expand All @@ -13,19 +14,30 @@

- name: Creates destination directory
# Workaround for #2372
file: state=directory mode=0700 dest=/root/.ssh/
file:
state: directory
mode: 0700
dest: /root/.ssh/

- name: Pushes user's rsa key to root's vagrant box (it's ok if this TASK fails)
# action: authorized_key user=root key='$FILE(~/.ssh/id_rsa.pub)'
# Workaround for #2372
copy: src=~/.ssh/id_rsa.pub dest=/root/.ssh/authorized_keys owner=root mode=0600
copy:
src: ~/.ssh/id_rsa.pub
dest: /root/.ssh/authorized_keys
owner: root
mode: 0600
register: rsa
ignore_errors: yes

- name: Pushes user's dsa key to root's vagrant box (it's NOT ok if both TASKs fail)
# action: authorized_key user=root key='$FILE(~/.ssh/id_dsa.pub)'
# Workaround for #2372
copy: src=~/.ssh/id_dsa.pub dest=/root/.ssh/authorized_keys owner=root mode=0600
copy:
src: ~/.ssh/id_dsa.pub
dest: /root/.ssh/authorized_keys
owner: root
mode: 0600
when: rsa|failed

- name: Checks if resolver is working properly (issues with some VBox/Host OS combinations)
Expand All @@ -34,12 +46,16 @@
ignore_errors: yes

- name: Pushes new resolver configuration if resolver fails
lineinfile: regexp="^nameserver " line="nameserver 8.8.8.8" dest=/etc/resolv.conf
lineinfile:
regexp: "^nameserver "
line: "nameserver 8.8.8.8"
dest: /etc/resolv.conf
when: ns|failed

- name: Checks if resolver is working properly with new nameserver
command: host -t A ansible.cc

- name: Final greeting
pause: prompt="Don't worry about all the red above; if you made it here, your Vagrant VMs are probably fine !
pause:
prompt: "Don't worry about all the red above; if you made it here, your Vagrant VMs are probably fine !
Please press [Enter]"
12 changes: 8 additions & 4 deletions step-04/apache.yml
@@ -1,4 +1,8 @@
- hosts: web
tasks:
- name: Installs apache web server
apt: pkg=apache2 state=installed update_cache=true
---
- hosts: web
tasks:
- name: Installs apache web server
apt:
pkg: apache2
state: installed
update_cache: true
60 changes: 38 additions & 22 deletions step-05/apache.yml
@@ -1,26 +1,42 @@
- hosts: web
tasks:
- name: Installs apache web server
apt: pkg=apache2 state=installed update_cache=true
---
- hosts: web
tasks:
- name: Installs apache web server
apt:
pkg: apache2
state: installed
update_cache: true

- name: Push default virtual host configuration
copy: src=files/awesome-app dest=/etc/apache2/sites-available/awesome-app.conf mode=0640
- name: Push default virtual host configuration
copy:
src: files/awesome-app
dest: /etc/apache2/sites-available/awesome-app.conf
mode: 0640

- name: Disable the default virtualhost
file: dest=/etc/apache2/sites-enabled/000-default.conf state=absent
notify:
- restart apache
- name: Disable the default virtualhost
file:
dest: /etc/apache2/sites-enabled/000-default.conf
state: absent
notify:
- restart apache

- name: Disable the default ssl virtualhost
file: dest=/etc/apache2/sites-enabled/default-ssl.conf state=absent
notify:
- restart apache
- name: Disable the default ssl virtualhost
file:
dest: /etc/apache2/sites-enabled/default-ssl.conf
state: absent
notify:
- restart apache

- name: Activates our virtualhost
file: src=/etc/apache2/sites-available/awesome-app.conf dest=/etc/apache2/sites-enabled/awesome-app.conf state=link
notify:
- restart apache

handlers:
- name: restart apache
service: name=apache2 state=restarted
- name: Activates our virtualhost
file:
src: /etc/apache2/sites-available/awesome-app.conf
dest: /etc/apache2/sites-enabled/awesome-app.conf
state: link
notify:
- restart apache

handlers:
- name: restart apache
service:
name: apache2
state: restarted
49 changes: 29 additions & 20 deletions step-06/apache.yml
@@ -1,25 +1,34 @@
- hosts: web
tasks:
- name: Installs apache web server
apt: pkg=apache2 state=installed update_cache=true
---
- hosts: web
tasks:
- name: Installs apache web server
apt:
pkg: apache2
state: installed
update_cache: true

- name: Push future default virtual host configuration
copy: src=files/awesome-app dest=/etc/apache2/sites-available/awesome-app.conf mode=0640
- name: Push future default virtual host configuration
copy:
src: files/awesome-app
dest: /etc/apache2/sites-available/awesome-app.conf
mode: 0640

- name: Activates our virtualhost
command: a2ensite awesome-app
- name: Activates our virtualhost
command: a2ensite awesome-app

- name: Check that our config is valid
command: apache2ctl configtest

- name: Deactivates the default virtualhost
command: a2dissite 000-default
- name: Check that our config is valid
command: apache2ctl configtest

- name: Deactivates the default ssl virtualhost
command: a2dissite default-ssl
notify:
- restart apache
- name: Deactivates the default virtualhost
command: a2dissite 000-default

handlers:
- name: restart apache
service: name=apache2 state=restarted
- name: Deactivates the default ssl virtualhost
command: a2dissite default-ssl
notify:
- restart apache

handlers:
- name: restart apache
service:
name: apache2
state: restarted
89 changes: 49 additions & 40 deletions step-07/apache.yml
@@ -1,40 +1,49 @@
- hosts: web
tasks:
- name: Installs apache web server
apt: pkg=apache2 state=installed update_cache=true

- name: Push future default virtual host configuration
copy: src=files/awesome-app dest=/etc/apache2/sites-available/awesome-app.conf mode=0640

- name: Deactivates the default virtualhost
command: a2dissite 000-default

- name: Activates our virtualhost
command: a2ensite awesome-app

- name: Check that our config is valid
command: apache2ctl configtest
register: result
ignore_errors: True

- name: Rolling back - Restoring old default virtualhost
command: a2ensite 000-default
when: result|failed

- name: Rolling back - Removing out virtualhost
command: a2dissite awesome-app
when: result|failed

- name: Rolling back - Ending playbook
fail: msg="Configuration file is not valid. Please check that before re-running the playbook."
when: result|failed

- name: Deactivates the default ssl virtualhost
command: a2dissite default-ssl

notify:
- restart apache

handlers:
- name: restart apache
service: name=apache2 state=restarted
---
- hosts: web
tasks:
- name: Installs apache web server
apt:
pkg: apache2
state: installed
update_cache: true

- name: Push future default virtual host configuration
copy:
src: files/awesome-app
dest: /etc/apache2/sites-available/awesome-app.conf
mode: 0640

- name: Deactivates the default virtualhost
command: a2dissite 000-default

- name: Activates our virtualhost
command: a2ensite awesome-app

- name: Check that our config is valid
command: apache2ctl configtest
register: result
ignore_errors: True

- name: Rolling back - Restoring old default virtualhost
command: a2ensite 000-default
when: result|failed

- name: Rolling back - Removing out virtualhost
command: a2dissite awesome-app
when: result|failed

- name: Rolling back - Ending playbook
fail: msg="Configuration file is not valid. Please check that before re-running the playbook."
when: result|failed

- name: Deactivates the default ssl virtualhost
command: a2dissite default-ssl

notify:
- restart apache

handlers:
- name: restart apache
service:
name: apache2
state: restarted
112 changes: 62 additions & 50 deletions step-08/apache.yml
@@ -1,50 +1,62 @@
- hosts: web
tasks:
- name: Updates apt cache
apt: update_cache=true

- name: Installs necessary packages
apt: pkg={{ item }} state=latest
with_items:
- apache2
- libapache2-mod-php5
- git

- name: Push future default virtual host configuration
copy: src=files/awesome-app dest=/etc/apache2/sites-available/awesome-app.conf mode=0640

- name: Activates our virtualhost
command: a2ensite awesome-app

- name: Check that our config is valid
command: apache2ctl configtest
register: result
ignore_errors: True

- name: Rolling back - Restoring old default virtualhost
command: a2ensite 000-default
when: result|failed

- name: Rolling back - Removing out virtualhost
command: a2dissite awesome-app
when: result|failed

- name: Rolling back - Ending playbook
fail: msg="Configuration file is not valid. Please check that before re-running the playbook."
when: result|failed

- name: Deploy our awesome application
git: repo=https://github.com/leucos/ansible-tuto-demosite.git dest=/var/www/awesome-app
tags: deploy

- name: Deactivates the default virtualhost
command: a2dissite 000-default

- name: Deactivates the default ssl virtualhost
command: a2dissite default-ssl
notify:
- restart apache

handlers:
- name: restart apache
service: name=apache2 state=restarted
---
- hosts: web
tasks:
- name: Updates apt cache
apt:
update_cache: true

- name: Installs necessary packages
apt:
pkg: "{{ item }}"
state: latest
with_items:
- apache2
- libapache2-mod-php5
- git

- name: Push future default virtual host configuration
copy:
src: files/awesome-app
dest: /etc/apache2/sites-available/awesome-app.conf
mode: 0640

- name: Activates our virtualhost
command: a2ensite awesome-app

- name: Check that our config is valid
command: apache2ctl configtest
register: result
ignore_errors: True

- name: Rolling back - Restoring old default virtualhost
command: a2ensite 000-default
when: result|failed

- name: Rolling back - Removing out virtualhost
command: a2dissite awesome-app
when: result|failed

- name: Rolling back - Ending playbook
fail:
msg: "Configuration file is not valid. Please check that before re-running the playbook."
when: result|failed

- name: Deploy our awesome application
git:
repo: https://github.com/leucos/ansible-tuto-demosite.git
dest: /var/www/awesome-app
tags: deploy

- name: Deactivates the default virtualhost
command: a2dissite 000-default

- name: Deactivates the default ssl virtualhost
command: a2dissite default-ssl
notify:
- restart apache

handlers:
- name: restart apache
service:
name: apache2
state: restarted

0 comments on commit 4db62f5

Please sign in to comment.