- name: Check vhost
- command: "test -L /etc/apache2/sites-enabled/{{ virtual_host }}.conf"
- failed_when: false
- register: vhost
- changed_when: vhost.rc != 0
+ stat:
+ path: "/etc/apache2/sites-enabled/{{ virtual_host }}.conf"
+ register: vhost_conf
- name: Add vhost
import_tasks: add-vhost.yml
- when: vhost.rc != 0
+ when: not vhost_conf.stats.exists
- name: Run dehydrated for the vhost
import_tasks: dehydrated.yml
- when: vhost.rc != 0
+ when: not vhost_conf.stats.exists
- name: Check apache
- command: test -L /etc/apache2/conf-enabled/001-phd.conf
- failed_when: false
- register: apache
- changed_when: apache.rc != 0
+ stat:
+ path: /etc/apache2/conf-enabled/001-phd.conf
+ register: phd_conf
- debug:
msg: "apache has already been configured"
- when: apache.rc == 0
+ when: not phd_conf.stats.exists
- name: Install apache
become: true
purge: yes
state: latest
update_cache: yes
- when: apache.rc != 0
+ when: not phd_conf.stats.exists
- name: Enable SSL module
become: true
command: a2enmod ssl
notify: Reload apache
- when: apache.rc != 0
+ when: not phd_conf.stats.exists
- name: Configure apache
become: true
group: root
mode: '0640'
force: no
- when: apache.rc != 0
+ when: not phd_conf.stats.exists
- name: Enable config
become: true
command: a2enconf 001-phd
notify: Reload apache
- when: apache.rc != 0
+ when: not phd_conf.stats.exists
- name: Configure logrotate
become: true
- name: Test if dehydrated is already cloned
- local_action: command test -f /usr/local/src/LetsEncrypt/dehydrated/.git/config
- failed_when: false
- register: dehydrated_exist
- changed_when: dehydrated_exist.rc != 0
+ local_action:
+ module: stat
+ path: /usr/local/src/LetsEncrypt/dehydrated/.git/config
+ register: dehydrated
- name: Install git
local_action:
purge: yes
state: latest
update_cache: yes
- when: dehydrated_exist.rc != 0
+ when: dehydrated.stat.exists
- name: Prepare to clone dehydrated
local_action:
module: file
path: /usr/local/src/LetsEncrypt
state: directory
- when: dehydrated_exist.rc != 0
+ when: dehydrated.stat.exists
- name: Clone dehydrated
local_action:
module: git
repo: https://github.com/lukas2511/dehydrated.git
dest: /usr/local/src/LetsEncrypt
- when: dehydrated_exist.rc != 0
+ when: dehydrated.stat.exists
- name: Prepare the server to syncronize dehydrated
become: true
- name: Test if user phd already exists
- command: test -f ~/.profile -a -f ~/.shellrc
- failed_when: false
- register: phd_exist
- changed_when: phd_exist.rc != 0
+ stat:
+ path: "{{ item }}"
+ register: phd_exists
+ loop: ['~/.profile', '~/.shellrc']
- debug:
msg: "User phd has already been created"
- when: phd_exist.rc == 0
+ when: phd_exists.results|selectattr('stat.exists')|list|length == 2
- name: Create and setup user phd
block:
unarchive:
src: ~/archive/STORE/phd/Home/phd.tar.bz2
dest: /home
- when: phd_exist.rc != 0
+ when: phd_exists.results|selectattr('stat.exists')|list|length == 2
- name: "Setup root mc - check mc links"
become: true
- command: test -L ~root/.cache/mc -a -L ~root/.config/mc -a -L ~root/.local/share/mc
- failed_when: false
+ stat:
+ path: "{{ item }}"
register: links_exist
- changed_when: links_exist.rc != 0
+ loop: ['~root/.cache/mc', '~root/.config/mc', '~root/.local/share/mc']
- debug:
msg: "mc links have already been created"
- when: links_exist.rc == 0
+ when: links_exist.results|selectattr('stat.islnk')|list|length == 3
- name: "Setup root mc - create directories for mc links"
become: true
state: directory
mode: "0700"
loop: ['.cache', '.config', '.local/share']
- when: links_exist.rc != 0
+ when: links_exist.results|selectattr('stat.islnk')|list|length == 3
- name: "Setup root mc - remove mc directories"
become: true
path: "~root/{{ item }}"
state: absent
loop: ['.cache/mc', '.config/mc', '.local/share/mc']
- when: links_exist.rc != 0
+ when: links_exist.results|selectattr('stat.islnk')|list|length == 3
- name: "Setup root mc - link mc directories (1)"
become: true
src: "../.mc"
force: yes
loop: ['.cache/mc', '.config/mc']
- when: links_exist.rc != 0
+ when: links_exist.results|selectattr('stat.islnk')|list|length == 3
- name: "Setup root mc - link mc directories (2)"
become: true
src: "../../.mc"
force: yes
loop: ['.local/share/mc']
- when: links_exist.rc != 0
+ when: links_exist.results|selectattr('stat.islnk')|list|length == 3
- name: "Setup root mc - overwrite files from ~phd/admin"
become: true
mode: "0600"
force: yes
loop: ['hotlist', 'ini', 'panels.ini']
-