]> git.phdru.name Git - ansible.git/commitdiff
Feat: Use module `stat` instead of command `test`
authorOleg Broytman <phd@phdru.name>
Sat, 27 Jul 2019 13:18:56 +0000 (16:18 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 27 Jul 2019 13:18:56 +0000 (16:18 +0300)
playbooks/debian/roles/add-apache-vhost/tasks/main.yml
playbooks/debian/roles/apache/tasks/main.yml
playbooks/debian/roles/install-dehydrated/tasks/main.yml
playbooks/debian/roles/phd/tasks/main.yml
playbooks/debian/roles/root/tasks/mc.yml

index 0133626c021d8b664b93446a6884de249833acd6..666cd77d7ce9c15a0d0fdee7cf880cba929bfb32 100644 (file)
@@ -1,13 +1,12 @@
 - 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
index f0481d91e1c0a80fcef3672125f20fc8d3602edd..b289d9419d2223378b721663adca2ff167b6c2dd 100644 (file)
@@ -1,12 +1,11 @@
 - 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
index dbd994c6c617627ef17e6dac40dce6e3d0863f50..7672bc86c05be347305e4db09d28f6bca6a21d3a 100644 (file)
@@ -1,8 +1,8 @@
 - 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
index 7ab7ba1d50574c21de7734da3b7dd3e2a5053812..4c00ec5d2d369e06b92bd489fa10d1df1ce921a7 100644 (file)
@@ -1,12 +1,12 @@
 - 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:
@@ -16,4 +16,4 @@
       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
index 655514aa69d4e9ff574f87e33014cdeafd6c557f..dbb78bad25e8639dc1a4e7d4f3e34284f15d6bdf 100644 (file)
@@ -1,13 +1,13 @@
 - 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
@@ -16,7 +16,7 @@
     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
@@ -24,7 +24,7 @@
     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
@@ -34,7 +34,7 @@
     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
@@ -44,7 +44,7 @@
     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
@@ -57,4 +57,3 @@
     mode: "0600"
     force: yes
   loop: ['hotlist', 'ini', 'panels.ini']
-