[jenkins-ci PATCH 2/5] guests: Figure out OS-dependent paths automatically

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When configuring a guest, we need to know the absolute path for
some commands and files; unfortunately, while most of them are
the same regardless of the OS, some of them don't.

Right now we hardcode such paths in the inventory, but it would
be better if we didn't have to do that: this commit introduces
a way to let Ansible figure out the paths for itself instead.

We're going to use it for more paths later on.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 guests/group_vars/all/main.yml                    |  5 ---
 guests/host_vars/libvirt-freebsd-10/main.yml      |  5 ---
 guests/host_vars/libvirt-freebsd-11/main.yml      |  5 ---
 guests/host_vars/libvirt-freebsd-current/main.yml |  5 ---
 guests/site.yml                                   |  1 +
 guests/tasks/paths.yml                            | 37 +++++++++++++++++++++++
 6 files changed, 38 insertions(+), 20 deletions(-)
 create mode 100644 guests/tasks/paths.yml

diff --git a/guests/group_vars/all/main.yml b/guests/group_vars/all/main.yml
index 4e05c66..b364acf 100644
--- a/guests/group_vars/all/main.yml
+++ b/guests/group_vars/all/main.yml
@@ -18,8 +18,3 @@ GI_TYPELIB_PATH: $VIRT_PREFIX/lib/girepository-1.0
 OSINFO_SYSTEM_DIR: $VIRT_PREFIX/share/osinfo
 PERL5LIB:
 PYTHONPATH:
-
-bash: /bin/bash
-java: /usr/bin/java
-su: /bin/su
-sudoers: /etc/sudoers
diff --git a/guests/host_vars/libvirt-freebsd-10/main.yml b/guests/host_vars/libvirt-freebsd-10/main.yml
index 487b3e8..ab5e367 100644
--- a/guests/host_vars/libvirt-freebsd-10/main.yml
+++ b/guests/host_vars/libvirt-freebsd-10/main.yml
@@ -4,11 +4,6 @@ ansible_python_interpreter: /usr/local/bin/python2
 PERL5LIB: $VIRT_PREFIX/lib/perl5/site_perl/mach/5.26
 PYTHONPATH: $VIRT_PREFIX/lib/python3.6/site-packages
 
-bash: /usr/local/bin/bash
-java: /usr/local/bin/java
-su: /usr/bin/su
-sudoers: /usr/local/etc/sudoers
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-freebsd-11/main.yml b/guests/host_vars/libvirt-freebsd-11/main.yml
index 487b3e8..ab5e367 100644
--- a/guests/host_vars/libvirt-freebsd-11/main.yml
+++ b/guests/host_vars/libvirt-freebsd-11/main.yml
@@ -4,11 +4,6 @@ ansible_python_interpreter: /usr/local/bin/python2
 PERL5LIB: $VIRT_PREFIX/lib/perl5/site_perl/mach/5.26
 PYTHONPATH: $VIRT_PREFIX/lib/python3.6/site-packages
 
-bash: /usr/local/bin/bash
-java: /usr/local/bin/java
-su: /usr/bin/su
-sudoers: /usr/local/etc/sudoers
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-freebsd-current/main.yml b/guests/host_vars/libvirt-freebsd-current/main.yml
index 487b3e8..ab5e367 100644
--- a/guests/host_vars/libvirt-freebsd-current/main.yml
+++ b/guests/host_vars/libvirt-freebsd-current/main.yml
@@ -4,11 +4,6 @@ ansible_python_interpreter: /usr/local/bin/python2
 PERL5LIB: $VIRT_PREFIX/lib/perl5/site_perl/mach/5.26
 PYTHONPATH: $VIRT_PREFIX/lib/python3.6/site-packages
 
-bash: /usr/local/bin/bash
-java: /usr/local/bin/java
-su: /usr/bin/su
-sudoers: /usr/local/etc/sudoers
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/site.yml b/guests/site.yml
index 46d2db6..063b0c6 100644
--- a/guests/site.yml
+++ b/guests/site.yml
@@ -48,6 +48,7 @@
         - flavor == "jenkins"
 
     # Configure environment. Needs to happen after installing packages
+    - include: tasks/paths.yml
     - include: tasks/bootloader.yml
     - include: tasks/services.yml
     - include: tasks/kludges.yml
diff --git a/guests/tasks/paths.yml b/guests/tasks/paths.yml
new file mode 100644
index 0000000..36b699f
--- /dev/null
+++ b/guests/tasks/paths.yml
@@ -0,0 +1,37 @@
+---
+- set_fact:
+    commands: {}
+    files: {}
+
+- name: 'Look for commands'
+  shell: 'which {{ item }} 2>/dev/null || true'
+  register: which
+  with_items:
+    - bash
+    - java
+    - su
+
+- name: 'Look for files'
+  shell: 'find /etc /usr/local/etc -name {{ item }} 2>/dev/null'
+  register: find
+  with_items:
+    - sudoers
+
+- set_fact:
+    commands: '{{ commands|combine({ item.item: item.stdout }) }}'
+  no_log: True
+  with_items:
+    '{{ which.results }}'
+
+- set_fact:
+    files: '{{ files|combine({ item.item: item.stdout }) }}'
+  no_log: True
+  with_items:
+    '{{ find.results }}'
+
+- name: 'Export paths'
+  set_fact:
+    bash: '{{ commands["bash"] }}'
+    java: '{{ commands["java"] }}'
+    su: '{{ commands["su"] }}'
+    sudoers: '{{ files["sudoers"] }}'
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux