Mic92 / ansible-lxc

Ansible Connection Plugin for lxc containers (https://linuxcontainers.org/)
GNU General Public License v3.0
17 stars 6 forks source link

what is the equivalent for "ansible_ssh_user" when using lxc-connector? #10

Open joaocc opened 9 years ago

joaocc commented 9 years ago

When running the controller in a vagrant vm with lxc installed locally, lxc creates a "/home/vagrant/.ansible" folder on the guest (chowned as root:root). However, the "vagrant" user is not defined in the guest.

I suspect (but am not sure) that this is leading to some weird behaviours:

How can I change the account as which ansible connects to the guest?

Thanks

joaocc commented 9 years ago

added the following command before:

- sudo: true
  get_url:
    url: "http://ppa.launchpad.net/ondrej/php5/ubuntu/dists/trusty/Release.gpg"
    dest: /tmp/test-php5-ppa.gpg
    force: yes

ansible -vvv

TASK: [ez123-web--php5 | DEBUG-1] ********************************************* 
    <h-lemp-1> THIS IS A LOCAL LXC DIR
    <h-lemp-1> REMOTE_MODULE get_url dest=/tmp/test-php5-ppa.gpg url=http://ppa.launchpad.net/ondrej/php5/ubuntu/dists/trusty/Release.gpg
    <h-lemp-1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1437528542.09-225157215014723 && echo $HOME/.ansible/tmp/ansible-tmp-1437528542.09-225157215014723']
    <h-lemp-1> PUT /tmp/tmpKr77ig TO /home/vagrant/.ansible/tmp/ansible-tmp-1437528542.09-225157215014723/get_url
    <h-lemp-1> EXEC ['/bin/sh', '-c', u'LANG=C LC_CTYPE=C /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1437528542.09-225157215014723/get_url; rm -rf /home/vagrant/.ansible/tmp/ansible-tmp-1437528542.09-225157215014723/ >/dev/null 2>&1']
    failed: [h-lemp-1] => {"dest": "/tmp/test-php5-ppa.gpg", "failed": true, "response": "Request failed: <urlopen error [Errno 111] Connection refused>", "state": "absent", "status_code": -1, "url": "http://ppa.launchpad.net/ondrej/php5/ubuntu/dists/trusty/Release.gpg"}
    msg: Request failed

    FATAL: all hosts have already failed -- aborting

running inside the guest (sudo lxc-console -n h-lemp-1)

    ubuntu@h-lemp-1:~$ curl http://ppa.launchpad.net/ondrej/php5/ubuntu/dists/trusty/Release.gpg
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.11 (GNU/Linux)

    iJwEAAECAAYFAlWmW+MACgkQT06gquUmemx17AP9H05MSi6UAis2u1nOh9nhqEN+
    l5I8C5hll/5/2DpeZqxfzJbyJ/Ni7M6hE/aDWC4JhOxkbKgNkFN3dXKGwWM+jVtK
    QGG1mhWVoTjoZo6tD5t0NKEH2rv/fti7kvyqoGGDqwd1FKAsxA8qZz85bZU7JGbi
    qd8yZ3m6xFr8GBV9Hno=
    =wLJS
    -----END PGP SIGNATURE-----
Mic92 commented 9 years ago

I suspect, lxc keeps the current working directory, when entering containers. Does it make a difference, if you change to / or /tmp/ on the host and start ansible from there?

joaocc commented 9 years ago

I think (more a hunch) that the problem is that LXC tries to connect with the same name as it has on the "origin" side. Since that user doesn't exist, it doesn't have a home directory (or something similar). We can try with "/tmp" but I would still prefer to be able to configure which user account is used when connecting.

Mic92 commented 9 years ago

It does not correlate with the user, because in that case it would be root and the directory would be in /root/.ansible. The vagrant user and its home should not exists in lxc container, therefor my idea was, that PWD environment variable is not overwritten, when entering a container.