# -*- mode: yaml; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -*-

---

- name: "DEBUG: proxy users.yml LOOP_USER"
  debug:
    verbosity: 1
    msg: "DEBUG: Including proxy users.yml LOOP_USER={{LOOP_USER}}"

# why LOOP_USER == portage
# was in testforge base.yml
- name: "gpgconf --list {{LOOP_USER}}"
  shell: |
    [ -d ~/.gpg ] || mkdir ~/.gpg
    gpgconf --list-dirs | grep 'socketdir\|homedir' | \
      sed -e 's/.*://' | \
      while read path; do
        [ -e $path ] || continue; chmod -R 'go-rwx' $path
    done
# wierd error
# TASK [proxy : ~/.gitconfig with proxy http] *****************************************An exception occurred during task execution. To see the full traceback, use -vvv. The error was: FileNotFoundError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/mnt/o/data/TestForge/src/ansible']
# failed: [pentoo] (item={'dest': '~portage/.gitconfig', 'owner': 'portage'}) => changed=false
  when: false

# Unable to look up a name or access an attribute in template string ({{ item.dest|expanduser }}).
- name: ~/.gitconfig pull
  blockinfile:
    dest: "{{ item.dest | expanduser }}"
    owner: "{{ item.owner }}"
    create: yes
    marker: "# {mark} ANSIBLE MANAGED BLOCK proxy pull"
    block: |
      [pull]
      # ff = true
      rebase = true
  with_items:
    - dest: "~{{LOOP_USER}}/.gitconfig"
      owner: "{{ LOOP_USER }}"
  ignore_errors: true

- block:

  - name: /etc/dirmngr/dirmngr.conf
    shell: |
      [ -e "/etc/dirmngr/dirmngr.conf" ] || exit 0
      [ -e "{{ item|expanduser }}" ] && exit 0
      [ -d "`dirname {{ item|expanduser }}`" ] || exit 0
      ln -s "/etc/dirmngr/dirmngr.conf" "{{ item|expanduser }}"
    with_items:
      - "~{{LOOP_USER}}/.gpg/dirmngr.conf"
    when:
      - not ansible_check_mode
    # FixMe
    ignore_errors: true

  when:
    - "LOOP_USER != 'portage'"

- name: cacert.org
  shell: |
    PREFIX=/var/local
    [ -d $PREFIX/net/Http//www.cacert.org/certs/ ] || \
      mkdir -p $PREFIX/net/Http//www.cacert.org/certs/
    [ -f $PREFIX/net/Http//www.cacert.org/certs/cacert.asc ] || \
      scurl.bash -P $PREFIX/net/Http/www.cacert.org/certs/ \
        -- http://www.cacert.org/certs/cacert.asc
    [ -f $PREFIX/net/Http//www.cacert.org/certs/CAcert_Class3Root_x14E228.crt ] || \
      scurl.bash -P $PREFIX/net/Http/www.cacert.org/certs/ \
        -- http://www.cacert.org/certs/CAcert_Class3Root_x14E228.crt
    [ -f $PREFIX/net/Http//www.cacert.org/certs/root_X0F.crt ] || \
      scurl.bash -P $PREFIX/net/Http/www.cacert.org/certs/ \
        http://www.cacert.org/certs/root_X0F.crt
     ls -l $PREFIX/net/Http//www.cacert.org/certs/

  ignore_errors: true
  when:
    - false
    - LOOP_USER != 'portage'
    - BASE_ARE_CONNECTED|default('') != ''

# git config --global http.sslversion tlsv1.3
