diff --git a/files/ansible_pull_sh b/files/hpf-ans/bin/ansible_pull.sh similarity index 100% rename from files/ansible_pull_sh rename to files/hpf-ans/bin/ansible_pull.sh diff --git a/files/hpf-ans/bin/get_hpf_facts.sh b/files/hpf-ans/bin/get_hpf_facts.sh new file mode 100644 index 0000000..bde2303 --- /dev/null +++ b/files/hpf-ans/bin/get_hpf_facts.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env sh + +if [ -z "${1:-}" ] ; then + echo "ERROR - ansible OS family unspecified." >&2 + exit 1 +fi + +ANSIBLE_OS_FAMILY="${1}" +shift + +useradd_D() { + + case "${ANSIBLE_OS_FAMILY}" in + Debian) + /usr/sbin/useradd -D + ;; + RedHat) + /usr/sbin/useradd -D + ;; + *) + echo "ERROR - Unknown ansible OS FAMILY \"${ANSIBLE_OS_FAMILY}\"." >&2 + exit 99 + ;; + esac +} + +user_vars() { + useradd_D | sed 's/.*=/hpf_fact_\L&/' +} + +#echo '{"hpf":' +#(user_vars; ) | jo +#echo '}' + +user_vars diff --git a/scraps/test-get_hpf_facts.yml b/scraps/test-get_hpf_facts.yml new file mode 100644 index 0000000..6894550 --- /dev/null +++ b/scraps/test-get_hpf_facts.yml @@ -0,0 +1,34 @@ +--- + +- name: test-get_hpf_facts.yml + hosts: all + + tasks: + + - name: Copy over get_hpf_facts.sh + ansible.builtin.copy: + src: hpf-ans/bin/get_hpf_facts.sh + dest: bin/get_hpf_facts.sh + owner: hpf-ans + group: hpf-ans + mode: u=rwx,go=gx + backup: true + + - name: Run get_hpf_facts.sh + ansible.builtin.command: + cmd: bin/get_hpf_facts.sh {{ ansible_facts["os_family"] }} + register: hpf_facts + changed_when: false + + - name: Convert k=v stdout into facts + ansible.builtin.set_fact: + "{{ item.split('=', 1)[0] }}": "{{ item.split('=', 1)[1] }}" + loop: "{{ hpf_facts.stdout.splitlines() }}" + + - name: Print all variables + ansible.builtin.debug: + var: hostvars[inventory_hostname] + + - name: Print skel + ansible.builtin.debug: + var: hpf_fact_skel diff --git a/scraps/test-get_useradd_settings.yml b/scraps/test-get_useradd_settings.yml new file mode 100644 index 0000000..d995639 --- /dev/null +++ b/scraps/test-get_useradd_settings.yml @@ -0,0 +1,70 @@ +--- + +- name: test-get_useradd_settings.sh + hosts: all + + tasks: + + - name: Copy over bin/get_useradd_settings.sh + ansible.builtin.copy: + src: hpf-ans/bin/get_useradd_settings.sh + dest: bin/get_useradd_settings.sh + owner: hpf-ans + group: hpf-ans + mode: u=rwx,go=gx + backup: true + + - name: Run get_useradd_settings.sh + ansible.builtin.command: + cmd: bin/get_useradd_settings.sh {{ ansible_facts["os_family"] }} + register: useradd_settings + changed_when: false + + - name: Convert k=v stdout into variables + ansible.builtin.set_fact: +# great_heath: +# - "{{ item.split('=', 1)[0] }}": "{{ item.split('=', 1)[1] }}" + "HPF_{{ item.split('=', 1)[0] }}": "{{ item.split('=', 1)[1] }}" +# "{{ item.split('=', 1)[0] | trim }}": "{{ item.split('=', 1)[1] | trim }}" + loop: "{{ useradd_settings.stdout.splitlines() }}" + + + +# - name: Convert key-value strings into variables +# vars: +# my_var: "SKEL= SKEL2=/etc/skel\nHEATH=great" +# ansible.builtin.set_fact: "{{ my_var }}" + +# ansible.builtin.set_fact: "{{ useradd_settings.stdout }}" + +# ansible.builtin.set_fact: "SKEL= SKEL2=/etc/skel\nHEATH=great" + +# ansible.builtin.set_fact: "{{ useradd_settings.stdout | from_yaml }}" + +# ansible.builtin.set_fact: "{{ useradd_settings.stdout }}" + +# ansible.builtin.set_fact: "SKEL2=/etc/skel\nHEATH=great" + +# - name: Convert key-value strings into variables +# ansible.builtin.set_fact: +# kv_vars: "{{ useradd_settings.stdout }}" + +# - name: Print ansible variables +# ansible.builtin.debug: +# var: vars + +# - name: Print SKEL +# ansible.builtin.debug: +# var: SKEL +# - name: Print heath.SKEL +# ansible.builtin.debug: +# var: heath.SKEL +# - name: Print SKEL2 +# ansible.builtin.debug: +# var: SKEL2 +# - name: Print HEATH +# ansible.builtin.debug: +# var: HEATH + - name: Print all variables + ansible.builtin.debug: + var: vars