Skip to content

Commit

Permalink
Merge pull request #3 from joe-speedboat/master
Browse files Browse the repository at this point in the history
Moved to dynamic task_dir vars
  • Loading branch information
joe-speedboat authored Sep 17, 2024
2 parents cc41e72 + 4f6536c commit fab6653
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
galaxy_info:
author: Chris Ruettimann
role_name: template
namespace: joe-speedboat
# namespace: joe-speedboat
description: Bitbull Template Ansible Role
min_ansible_version: 2.9
license: GPLv3
Expand Down
4 changes: 0 additions & 4 deletions tasks/fallback.yml

This file was deleted.

1 change: 0 additions & 1 deletion tasks/include-file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@
- "{{ vars['task_dir_' + role_name|split('.')|last] }}/shared/{{ include_file_name }}"
loop_control:
loop_var: include_file_path

...
16 changes: 13 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
set_fact:
ansible_distribution_combine: dummy

- name: Create rhelAll fact if needed when AlmaLinux, Rocky, RHEL
- name: Create rhelAll fact, useful when AlmaLinux, Rocky, RHEL, ... all use the same Ansible code base
set_fact:
ansible_distribution_combine: rhelAll
when: >
Expand Down Expand Up @@ -41,7 +41,7 @@
paths:
- /runner/requirements_roles
- "{{ lookup('env', 'PWD') }}/roles/{{role_path|basename}}/tasks"
- "{{ lookup('env', 'HOME') }}/.ansible/roles{{role_path|basename}}/tasks"
- "{{ lookup('env', 'HOME') }}/.ansible/roles/{{role_path|basename}}/tasks"
- "/usr/share/ansible/roles/{{role_path|basename}}/tasks"
- "/etc/ansible/roles/{{role_path|basename}}/tasks"
- "/runner/project/roles/{{role_path|basename}}/tasks"
Expand All @@ -57,6 +57,11 @@
register: found_task_dirs
no_log: True

- name: show tasks directory var
debug:
msg: "{{ 'task_dir_' + role_name|split('.')|last }}: {{ found_task_dirs.files[0].path|dirname }}"
verbosity: 1

- name: define tasks directory
set_fact:
"{{ 'task_dir_' + role_name|split('.')|last }}": "{{ found_task_dirs.files[0].path|dirname }}"
Expand Down Expand Up @@ -86,6 +91,11 @@
set_fact:
include_file_names: "{{ include_file_names | unique | sort }}"

- name: show playbooks
debug:
msg: "include_file_names: {{ include_file_names | unique | sort }}"
verbosity: 1

######## END: Get playbooks to run ########


Expand All @@ -97,4 +107,4 @@
with_items:
- "{{ include_file_names }}"
######## END: Execution part ########

...
31 changes: 28 additions & 3 deletions tests/ansible_setup_local.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash
#DESC: Setup and configure Ansible control node
#WHO: chris@bitbull.ch
#DATE: 20220202

# Copyright (c) Chris Ruettimann <chris@bitbull.ch>
# This software is licensed to you under the GNU General Public License.
# There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/gpl.txt

test -f /etc/os-release
if [ $? -ne 0 ]
Expand Down Expand Up @@ -97,6 +101,27 @@ then
test -d /etc/ansible/collections || mkdir /etc/ansible/collections ; chmod 755 /etc/ansible/collections
ansible-galaxy search joe-speedboat | cat

elif [ "$os_type$os_ver" == "rel9" ] #########################################################
then
subscription-manager repos --enable=$(dnf repolist --all | awk '{print $1}' | grep -i codeready | grep $(echo $VERSION |cut -d. -f1)-$(arch)-rpms | tail -1)
for PKG in git wget curl ansible-core
do
rpm -q $PKG >/dev/null 2>&1 && echo $PKG is already installed || dnf -y install $PKG
done
ansibleconfigfile="/etc/ansible/ansible.cfg"
test -d /etc/ansible || mkdir /etc/ansible ; chmod 755 /etc/ansible
test -d /etc/ansible/projects || mkdir /etc/ansible/projects ; chmod 700 /etc/ansible/projects
test -d /etc/ansible/playbooks || mkdir /etc/ansible/playbooks ; chmod 700 /etc/ansible/playbooks
test -d /etc/ansible/collections || mkdir /etc/ansible/collections ; chmod 755 /etc/ansible/collections
test -f $ansibleconfigfile && cp -anv $ansibleconfigfile $ansibleconfigfile.bak
ansible-config init --disabled -t all | sed -e 's|{{ ANSIBLE_HOME ~ "/|/etc/ansible/|g' -e 's|" }}||g' > $ansibleconfigfile
sed -i 's|^;inventory=|inventory=|' $ansibleconfigfile
sed -i 's|^;roles_path=|roles_path=|' $ansibleconfigfile
sed -i 's|^;collections_path=|collections_path=|' $ansibleconfigfile
sed -i 's|^;nocows=.*|nocows=True|' $ansibleconfigfile
test -f /etc/ansible/hosts || echo localhost > /etc/ansible/hosts
ansible-galaxy search joe-speedboat | cat

elif [ "$os_type$os_ver" == "rel_clone9" ] #########################################################
then
dnf -y config-manager --set-enabled crb
Expand Down

0 comments on commit fab6653

Please sign in to comment.