From 612f3326b63959f95e71daffe201b188b3f5b5a7 Mon Sep 17 00:00:00 2001 From: Lilian Roller Date: Wed, 24 Apr 2019 14:49:17 +0200 Subject: [PATCH] Optimize playbook workflow without defined username --- README.md | 2 +- tasks/main.yml | 9 +++++---- tests/playbook.yml | 2 +- travis/test.yml | 2 +- vars/main.yml | 2 ++ 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a492aad..4554b36 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Role Variables i3_applications: [] *ansible user* -i3wm_user: "{{ user }}" +i3wm_user: "{{ ansible_user_id }}" Example Playbook ---------------- diff --git a/tasks/main.yml b/tasks/main.yml index 6a5e800..5582544 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -30,15 +30,16 @@ owner: "{{ i3wm_user }}" - name: register i3 config file - action: stat path="~/.config/i3/config" + action: stat path="/home/{{ i3wm_user }}/.config/i3/config" register: "config_file" + - name: backup i3 config file block: - name: backup i3 config file if exists copy: - src: ~/.config/i3/config - dest: ~/.config/i3/config.bak + src: "/home/{{ i3wm_user }}/.config/i3/config" + dest: "/home/{{ i3wm_user }}/.config/i3/config.bakup" remote_src: true when: config_file.stat.exists @@ -48,7 +49,7 @@ dest: "/home/{{ i3wm_user }}/.config/i3/config" - name: check i3 config file - command: i3 -C + command: "i3 -C -c /home/{{ i3wm_user }}/.config/i3/config" register: check_config_response failed_when: check_config_response.stdout.find('ERROR') != -1 rescue: diff --git a/tests/playbook.yml b/tests/playbook.yml index 6c0b7f8..dcf392f 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,6 +1,6 @@ --- - hosts: all - user: vagrant + i3wm_user: vagrant vars: diff --git a/travis/test.yml b/travis/test.yml index 247d20e..be3d5a2 100644 --- a/travis/test.yml +++ b/travis/test.yml @@ -1,6 +1,6 @@ --- - hosts: all vars: - user: "{{ ansible_user }}" + i3wm_user: "{{ ansible_user }}" roles: - travis_test diff --git a/vars/main.yml b/vars/main.yml index 1918562..a8b25bc 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -30,3 +30,5 @@ __i3_workspaces: - workspace: id: 0 name: " 0 " + +user: "{{ i3wm_user }}"