base_role/tasks/users.yml

202 lines
6.1 KiB
YAML

# -*- mode: yaml; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -*-
---
- name: "base users.yml {{LOOP_USER}}"
debug:
verbosity: 3
msg: "base users.yml {{LOOP_USER}} en http_proxy={{lookup('env', 'http_proxy')|default('')}}"
- name: "make ~/.config/testforge/"
file:
path: "{{ item|expanduser }}"
state: directory
mode: 0700
with_items:
#? - "~{{LOOP_USER}}"
- "~{{LOOP_USER}}/{{ BASE_USER_CONFIG_DIR }}"
- "~{{LOOP_USER}}/{{ BASE_USER_CONFIG_DIR }}/facts.d"
- "{{ BASE_TESTFORGE_YML|dirname }}"
# An exception occurred during task execution. The error was: _os.mkdir(file, 0700)
# msg: Unexpected failure during module execution.
ignore_errors: true
- name: ln -s 1777 /var/tmp/.ansible
shell: |
[ ! -d /var/tmp/.ansible ] && mkdir /var/tmp/.ansible && chmod 1777 /var/tmp/.ansible
[ -d ~/.ansible ] || mkdir ~/.ansible
[ -d ~/.ansible/tmp ] && [ -h ~/.ansible/tmp ] && exit 0
[ -h ~/.ansible/tmp ] || ln -s /var/tmp/.ansible ~/.ansible/tmp
exit 0
- name: "stat ~/.config/testforge/facts.d/testforge.yml"
stat:
path: "{{ BASE_TESTFORGE_YML }}"
register: base_testforge_ini_exists
- block:
- name: "make vagrant RO directories base"
file:
path: "{{ item|expanduser }}"
state: directory
mode: 0700
with_items:
- "~{{LOOP_USER}}/.cache"
- "~{{LOOP_USER}}/.config"
- "~{{LOOP_USER}}/.gpg"
- "~{{LOOP_USER}}/.local"
- "~{{LOOP_USER}}/.local/lib"
- "~{{LOOP_USER}}/.ssh"
# - name: "make vagrant RO files base"
# template or skel this
- block:
- name: "create ~/.config/testforge/facts.d/testforge.yml BOF"
lineinfile:
dest: "{{ BASE_TESTFORGE_YML }}"
insertbefore: BOF
mode: 0600
create: yes
regexp: "# -.- mode: yaml; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -.-"
line: "# -*- mode: yaml; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -*-"
register: base_create_testforge_yml
when: not base_testforge_ini_exists.stat.exists
- name: "~/.config/testforge/facts.d/testforge.yml VERSION"
blockinfile:
dest: "{{ BASE_TESTFORGE_YML }}"
create: false
insertafter: "# -.- mode: yaml; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -.-"
marker: "# {mark} ANSIBLE MANAGED BLOCK base [{{ elt.name }}]"
# lookup('vars', '{{ elt.name }}')
block: |
{{ elt.name }}: "{{ elt.val }}"
with_items:
- name: "TESTFORGE_VERSION"
val: "{{ TESTFORGE_VERSION|default('1.0') }}"
loop_control:
loop_var: elt
- name: "stat ~/.config/testforge/facts.d/testforge.yml"
stat:
path: "{{ BASE_TESTFORGE_YML }}"
register: testforge_ini_exists
- name: "including testforge.yml"
debug:
msg: "INFO: including {{BASE_TESTFORGE_YML}}"
when: testforge_ini_exists.stat.exists
- name: "WARN: NOT including testforge.yml"
debug:
msg: "WARN: NOT including {{BASE_TESTFORGE_YML}}"
when: not testforge_ini_exists.stat.exists
- name: "slurp REMOTE testforge.yml"
slurp:
src: "{{ BASE_TESTFORGE_YML }}"
register: testforge_user_yml
when: testforge_ini_exists.stat.exists
# Bug: This is NOT setting the value of the variables, but the include_vars does.
# Is this some kind of precedence issue?
- name: "set_fact testforge_user_yml"
set_fact:
# cacheable changes the persistance AND precedence
# cacheable: true
args: "{{ testforge_user_yml['content']|b64decode }}"
when: testforge_ini_exists.stat.exists
- name: "DEBUG: testforge_user_yml defined - does not error if not defined!"
# var: does not error if not defined!
debug:
var: TESTFORGE_VERSION
# finally fails in 2.8.12
ignore_errors: true
# set_fact fails silently on erroroneous content - an equals instead of a colon
- block:
- name: "DEBUG: testforge_user_yml contents"
debug:
verbosity: 1
msg: "{{ testforge_user_yml['content']|b64decode|to_yaml }}"
- name: "make a tempfile"
tempfile:
state: file
# path:
delegate_to: localhost
register: testforge_user_yml_file
- name: "copy testforge_user_yml_file to tempfile"
copy:
dest: "{{testforge_user_yml_file.path}}"
content: "{{ testforge_user_yml['content']|b64decode }}"
delegate_to: localhost
- name: "include_vars {{testforge_user_yml_file.path}}"
include_vars: "{{testforge_user_yml_file.path}}"
- name: "DEBUG: TESTFORGE_VERSION defined"
# msg: will error if not defined!
debug:
msg: "TESTFORGE_VERSION={{ TESTFORGE_VERSION }}"
when:
- not ansible_check_mode # needed
- base_testforge_ini_exists.stat.exists
# and TESTFORGE_VERSION|default('') != ''
rescue:
- debug:
msg: "ERROR: RESCUE reading in testforge_user_yml_file "
check_mode: false
- name: "make pip dirs"
file:
path: "{{ item.dest | expanduser }}"
state: directory
owner: "{{ BOX_USER_NAME }}"
group: "{{ BOX_ALSO_GROUP }}"
mode: "{{ item.mode }}"
with_items:
- {dest: "~{{LOOP_USER}}/.cache/pip", mode: "0775" }
- {dest: "~{{LOOP_USER}}/.local/{{BASE_LIB}}", mode: "0755" }
# could be symlinks
ignore_errors: true
- name: "make .local symlinks dirs for pip --user"
file:
src: "{{ item.src }}"
dest: "{{ item.dest | expanduser }}"
state: link
with_items:
- src: "{{USR_LOCAL}}/{{LIB}}/python{{BASE_PYTHON2_MINOR}}"
dest: "~{{LOOP_USER}}/.local/{{LIB}}/python{{BASE_PYTHON2_MINOR}}"
- src: "{{USR_LOCAL}}/{{LIB}}/python{{BASE_PYTHON3_MINOR}}"
dest: "~{{LOOP_USER}}/.local/{{LIB}}/python{{BASE_PYTHON3_MINOR}}"
- src: "{{USR_LOCAL}}/bin"
dest: "~{{LOOP_USER}}/.local/bin"
when:
- not ansible_check_mode
- name: "I think this is right"
file:
src: "{{ item.src | expanduser }}"
dest: "{{ item.dest | expanduser }}"
state: link
with_items:
- dest: "~{{LOOP_USER}}/.local/lib64"
src: "~{{LOOP_USER}}/.local/lib"
mode: "0755"
ignore_errors: true
when:
- not ansible_check_mode
- "BASE_LIB == 'lib64'"