From 47e10569f8deef28895e3cc7b2eb6e7a3a7bbba6 Mon Sep 17 00:00:00 2001 From: Sam Al-Sapti Date: Tue, 30 Jan 2024 20:55:48 +0100 Subject: [PATCH] Prepare for multiple inventories --- infrastructure.ini | 8 ++++++++ infrastructure.yml | 12 ++++++++++++ inventory.ini | 6 ------ site.yml | 1 - tools/cmd.sh | 7 ++++++- tools/reboot.sh | 7 ++++++- 6 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 infrastructure.ini create mode 100644 infrastructure.yml diff --git a/infrastructure.ini b/infrastructure.ini new file mode 100644 index 0000000..4bbc01b --- /dev/null +++ b/infrastructure.ini @@ -0,0 +1,8 @@ +[control_infra] +sapt-labx-ctl01 + +[controlservers:children] +control_infra + +[infrastructure:children] +controlservers diff --git a/infrastructure.yml b/infrastructure.yml new file mode 100644 index 0000000..f2ee307 --- /dev/null +++ b/infrastructure.yml @@ -0,0 +1,12 @@ +# vim: ft=yaml.ansible +# code: language=ansible +--- +- name: Run playbook + hosts: all + become: true + gather_facts: true + tasks: + - name: Include role 'ctl-common' + ansible.builtin.include_role: + name: ctl-common + when: hostname in groups['controlservers'] diff --git a/inventory.ini b/inventory.ini index 3313db7..e2769ac 100644 --- a/inventory.ini +++ b/inventory.ini @@ -22,9 +22,6 @@ sapt-labr-prx01 # [monitor_shrd] # sapt-labr-mon01 -# [control_infra] -# sapt-labx-ctl01 - [production:children] app_prod db_prod @@ -61,6 +58,3 @@ proxy_shrd production staging shared - -# [infrastructure:children] -# control_infra diff --git a/site.yml b/site.yml index 248192a..61b52ca 100644 --- a/site.yml +++ b/site.yml @@ -3,7 +3,6 @@ --- - name: Run playbook hosts: all - remote_user: ansible become: true gather_facts: true tasks: diff --git a/tools/cmd.sh b/tools/cmd.sh index d8188b1..2218051 100755 --- a/tools/cmd.sh +++ b/tools/cmd.sh @@ -1,6 +1,11 @@ #!/usr/bin/env bash +if [[ $1 == "-i" ]]; then + ARGS="-i $2" + shift 2 +fi + HOSTS="$1" CMD="$2" -ansible -b -u ansible -m shell -a "$CMD" "$HOSTS" +eval "ansible $ARGS -b -m shell -a \"$CMD\" \"$HOSTS\"" diff --git a/tools/reboot.sh b/tools/reboot.sh index 9cdb988..b995d35 100755 --- a/tools/reboot.sh +++ b/tools/reboot.sh @@ -1,5 +1,10 @@ #!/usr/bin/env bash +if [[ $1 == "-i" ]]; then + ARGS="-i $2" + shift 2 +fi + HOSTS="$1" -ansible -b -u ansible -m reboot "$HOSTS" +eval "ansible $ARGS -b -m reboot \"$HOSTS\""