# Verify the value of the Connection.homedir attribute is as expected.

- name: integration/connection/home_dir.yml
  hosts: test-targets
  tasks:
    - include_tasks: ../_mitogen_only.yml

    - name: "Find out root's homedir."
      # Runs first because it blats regular Ansible facts with junk, so
      # non-become run fixes that up.
      setup:
      become: true
      register: root_facts

    - name: "Find regular homedir"
      setup:
      register: user_facts

    - name: "Verify Connection.homedir correct when become:false"
      mitogen_action_script:
        script: |
          self._connection._connect()
          assert self._connection.homedir == "{{user_facts.ansible_facts.ansible_user_dir}}", {
            "connection homedir": self._connection.homedir,
            "homedir from facts": "{{user_facts.ansible_facts.ansible_user_dir}}"
          }

    - name: "Verify Connection.homedir correct when become:true"
      become: true
      mitogen_action_script:
        script: |
          self._connection._connect()
          assert self._connection.homedir == "{{root_facts.ansible_facts.ansible_user_dir}}", {
            "connection homedir": self._connection.homedir,
            "homedir from facts": "{{root_facts.ansible_facts.ansible_user_dir}}"
          }
  tags:
    - home_dir
    - mitogen_only
