# issue #409.
# setns is hard -- it wants to do superuser syscalls, so we must run it in a
# child Ansible via sudo. But that only works if sudo works.

- name: integration/stub_connections/setns_lxc.yml
  hosts: test-targets
  gather_facts: false
  any_errors_fatal: false
  connection: local
  vars:
    ansible_python_interpreter: "{{ ansible_playbook_python }}"
  tasks:
    - include_tasks: ../_mitogen_only.yml
    - include_tasks: _end_play_if_not_sudo_linux.yml

    - name: Run stub-lxc-info.py
      environment:
        ANSIBLE_CALLBACK_RESULT_FORMAT: json
        ANSIBLE_LOAD_CALLBACK_PLUGINS: "false"
        ANSIBLE_STRATEGY:  "{{ lookup('env', 'ANSIBLE_STRATEGY') | mandatory }}"
        ANSIBLE_VERBOSITY: "{{ ansible_verbosity }}"
      command: |
        sudo -nE "{{lookup('env', 'VIRTUAL_ENV')}}/bin/ansible"
        -i localhost,
        -c setns
        -e mitogen_kind=lxc
        -e ansible_python_interpreter="{{ ansible_playbook_python }}"
        -e mitogen_lxc_info_path={{git_basedir}}/tests/data/stubs/stub-lxc-info.py
        -m shell
        -a "echo hi"
        -u root
        localhost
      args:
        chdir: ../..
        warn: "{{ False if ansible_version_major_minor is version('2.10', '<=', strict=True) else omit }}"
      register: result

    - assert:
        that: result.rc == 0
        fail_msg: |
          result={{ result }}
  tags:
    - stns_lxc
    - mitogen_only
