# -*- mode: yaml; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -*-
---
- name: "DEBUG: ansible-gentoo_install portage  ansible_shell_executable={{ansible_shell_executable}}"
  debug:
    verbosity: 1
    msg: "DEBUG: ansible-gentoo_install portage ansible_shell_executable={{ansible_shell_executable}}"

- name: test we are in the chroot
  shell: |
    df | grep /mnt/gentoo && exit 1

- name: portage make.conf settings
  lineinfile:
    dest: /etc/portage/make.conf
    line: '{{ item.key }}="{{ item.value }}"'
    regexp: '^{{ item.key }}='
  with_dict: "{{ AGI_install_portage_makeconf_default | combine( AGI_install_portage_makeconf | default({}) ) }}"
  loop_control:
    label: "{{ item.key }}"

# Using blockinfile as a workaround to 'copy' not working with the chroot hack
- name: other portage config files
  blockinfile:
    dest: /etc/portage/{{ item.key }}
    content: "{{ item.value }}"
    owner: root
    mode: '0644'
    create: yes
  with_dict: "{{ AGI_install_portage_conf_files | default({}) }}"
  loop_control:
    label: "{{ item.key }}"
  when: false

- name: install portage tree snapshot
  command: emerge-webrsync
  when: false

#- name: update portage tree
#  command: emerge --sync

# The 'portage' module doesn't work without the 'equery' command available,
# which is provided by the gentoolkit package
- name: install gentoolkit package
  command: emerge app-portage/gentoolkit
  args:
    creates: /var/db/pkg/app-portage/gentoolkit-*
  when: false # old bug in portage?
