Hi, A LXC container doesn't run sshd. To run ansible against one you need to use a custom connection plugin like this 1). You can compare with the custom connection plugin used for WinRM which is in the docs.
When you have a working example it would be awesome if you could post it here. 1) https://github.com/Mic92/ansible-lxc/blob/master/README.md On Oct 8, 2017 21:33, <[email protected]> wrote: > Hi All, > > I am trying to provision an LXC container using the ansible remote > provisioner. But I am facing the issue where ansible is not able to connect > to the machine. > > The packer template(template.json) is given below > > ---- > { > "variables": { > "template_name": "ubuntu", > "template_parameters": "SUITE=trusty", > "image_name": "rtbrick-generic", > "version": "17.10.1", > }, > "provisioners": [ > { > "type": "ansible", > "playbook_file": "rtbrick-setup-lxc-image.yaml", > "ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False", > "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o > ControlPersist=60s'", "ANSIBLE_NOCOLOR=True" ], > "extra_arguments": [ "--extra-vars", "ansible_sudo_pass=ubuntu > ansible_ssh_pass=ubuntu ], > "groups": ["lxc_host"], > "host_alias": "rtbrick", > "user": "ubuntu" > } > ], > "builders": [ > { > "type": "lxc", > "name": "lxc-{{user `image_name`}}-{{user `version`}}", > "output_directory": "lxc-{{user `image_name`}}-{{user `version`}}", > "template_name": "{{user `template_name`}}", > "config_file": "/usr/share/lxc/config/ubuntu.common.conf", > "container_name": "rtbrick" > } > ] > } > > ---- > > The ansible playbook(rtbrick-setup-lxc-image.yaml) is given below: > > ----- > - name: Setup the Rtbrick containers on the host > sudo: True > hosts: lxc_host > tasks: > - name: Create BD config directory > file: "path=/etc/rtbrick/bd/config state=directory" > > > ----- > > > > > After running the command - packer build template.json, these are the > messages I get - > lxc-rtbrick-generic-17.10.1 output will be in this color. > > ==> lxc-rtbrick-generic-17.10.1: Creating container... > ==> lxc-rtbrick-generic-17.10.1: Waiting for container to finish init... > ==> lxc-rtbrick-generic-17.10.1: Container finished init! > ==> lxc-rtbrick-generic-17.10.1: Provisioning with shell script: > scripts/base.sh > lxc-rtbrick-generic-17.10.1: Hit http://ppa.launchpad.net trusty > InRelease > lxc-rtbrick-generic-17.10.1: Hit http://ppa.launchpad.net trusty/main > amd64 Packages > lxc-rtbrick-generic-17.10.1: Hit http://ppa.launchpad.net trusty/main > Translation-en > lxc-rtbrick-generic-17.10.1: Ign http://np.archive.ubuntu.com trusty > InRelease > lxc-rtbrick-generic-17.10.1: Get:1 http://np.archive.ubuntu.com > trusty-updates InRelease [65.9 kB] > lxc-rtbrick-generic-17.10.1: Get:2 http://np.archive.ubuntu.com > trusty-security InRelease [65.9 kB] > lxc-rtbrick-generic-17.10.1: Get:3 http://np.archive.ubuntu.com > trusty Release.gpg [933 B] > lxc-rtbrick-generic-17.10.1: Get:4 http://np.archive.ubuntu.com > trusty-updates/main amd64 Packages [1,027 kB] > lxc-rtbrick-generic-17.10.1: Get:5 http://np.archive.ubuntu.com > trusty-updates/restricted amd64 Packages [17.1 kB] > lxc-rtbrick-generic-17.10.1: Get:6 http://np.archive.ubuntu.com > trusty-updates/universe amd64 Packages [429 kB] > lxc-rtbrick-generic-17.10.1: Get:7 http://np.archive.ubuntu.com > trusty-updates/multiverse amd64 Packages [14.3 kB] > lxc-rtbrick-generic-17.10.1: Get:8 http://np.archive.ubuntu.com > trusty-updates/main Translation-en [507 kB] > lxc-rtbrick-generic-17.10.1: Get:9 http://np.archive.ubuntu.com > trusty-updates/multiverse Translation-en [7,430 B] > lxc-rtbrick-generic-17.10.1: Get:10 http://np.archive.ubuntu.com > trusty-updates/restricted Translation-en [3,978 B] > lxc-rtbrick-generic-17.10.1: Get:11 http://np.archive.ubuntu.com > trusty-updates/universe Translation-en [232 kB] > lxc-rtbrick-generic-17.10.1: Get:12 http://np.archive.ubuntu.com > trusty Release [58.5 kB] > lxc-rtbrick-generic-17.10.1: Get:13 http://np.archive.ubuntu.com > trusty-security/main amd64 Packages [672 kB] > lxc-rtbrick-generic-17.10.1: Get:14 http://np.archive.ubuntu.com > trusty-security/restricted amd64 Packages [14.0 kB] > lxc-rtbrick-generic-17.10.1: Get:15 http://np.archive.ubuntu.com > trusty-security/universe amd64 Packages [188 kB] > lxc-rtbrick-generic-17.10.1: Get:16 http://np.archive.ubuntu.com > trusty-security/multiverse amd64 Packages [4,116 B] > lxc-rtbrick-generic-17.10.1: Get:17 http://np.archive.ubuntu.com > trusty-security/main Translation-en [363 kB] > lxc-rtbrick-generic-17.10.1: Get:18 http://np.archive.ubuntu.com > trusty-security/multiverse Translation-en [2,201 B] > lxc-rtbrick-generic-17.10.1: Get:19 http://np.archive.ubuntu.com > trusty-security/restricted Translation-en [3,491 B] > lxc-rtbrick-generic-17.10.1: Get:20 http://np.archive.ubuntu.com > trusty-security/universe Translation-en [108 kB] > lxc-rtbrick-generic-17.10.1: Get:21 http://np.archive.ubuntu.com > trusty/main amd64 Packages [1,350 kB] > lxc-rtbrick-generic-17.10.1: Get:22 http://np.archive.ubuntu.com > trusty/restricted amd64 Packages [13.0 kB] > lxc-rtbrick-generic-17.10.1: Get:23 http://np.archive.ubuntu.com > trusty/universe amd64 Packages [5,859 kB] > lxc-rtbrick-generic-17.10.1: Get:24 http://np.archive.ubuntu.com > trusty/multiverse amd64 Packages [132 kB] > lxc-rtbrick-generic-17.10.1: Get:25 http://np.archive.ubuntu.com > trusty/main Translation-en [762 kB] > lxc-rtbrick-generic-17.10.1: Get:26 http://np.archive.ubuntu.com > trusty/multiverse Translation-en [102 kB] > lxc-rtbrick-generic-17.10.1: Get:27 http://np.archive.ubuntu.com > trusty/restricted Translation-en [3,457 B] > lxc-rtbrick-generic-17.10.1: Get:28 http://np.archive.ubuntu.com > trusty/universe Translation-en [4,089 kB] > lxc-rtbrick-generic-17.10.1: Ign http://np.archive.ubuntu.com > trusty/main Translation-en_IN > lxc-rtbrick-generic-17.10.1: Ign http://np.archive.ubuntu.com > trusty/multiverse Translation-en_IN > lxc-rtbrick-generic-17.10.1: Ign http://np.archive.ubuntu.com > trusty/restricted Translation-en_IN > lxc-rtbrick-generic-17.10.1: Ign http://np.archive.ubuntu.com > trusty/universe Translation-en_IN > lxc-rtbrick-generic-17.10.1: Fetched 16.1 MB in 6min 35s (40.7 kB/s) > lxc-rtbrick-generic-17.10.1: Reading package lists... > lxc-rtbrick-generic-17.10.1: Reading package lists... > lxc-rtbrick-generic-17.10.1: Building dependency tree... > lxc-rtbrick-generic-17.10.1: Reading state information... > lxc-rtbrick-generic-17.10.1: The following packages will be upgraded: > lxc-rtbrick-generic-17.10.1: ca-certificates git git-man libidn11 > libidn11-dev libvirt-dev libvirt0 > lxc-rtbrick-generic-17.10.1: 7 upgraded, 0 newly installed, 0 to > remove and 0 not upgraded. > lxc-rtbrick-generic-17.10.1: Need to get 4,664 kB of archives. > lxc-rtbrick-generic-17.10.1: After this operation, 44.0 kB disk space > will be freed. > lxc-rtbrick-generic-17.10.1: Get:1 http://np.archive.ubuntu.com/ > ubuntu/ trusty-updates/main libidn11-dev amd64 1.28-1ubuntu2.2 [519 kB] > lxc-rtbrick-generic-17.10.1: Get:2 http://np.archive.ubuntu.com/ > ubuntu/ trusty-updates/main libidn11 amd64 1.28-1ubuntu2.2 [94.6 kB] > lxc-rtbrick-generic-17.10.1: Get:3 http://np.archive.ubuntu.com/ > ubuntu/ trusty-updates/main ca-certificates all 20170717~14.04.1 [167 kB] > lxc-rtbrick-generic-17.10.1: Get:4 http://np.archive.ubuntu.com/ > ubuntu/ trusty-updates/main git-man all 1:1.9.1-1ubuntu0.7 [699 kB] > lxc-rtbrick-generic-17.10.1: Get:5 http://np.archive.ubuntu.com/ > ubuntu/ trusty-updates/main git amd64 1:1.9.1-1ubuntu0.7 [2,252 kB] > lxc-rtbrick-generic-17.10.1: Get:6 http://np.archive.ubuntu.com/ > ubuntu/ trusty-updates/main libvirt-dev amd64 1.2.2-0ubuntu13.1.23 [102 > kB] > lxc-rtbrick-generic-17.10.1: Get:7 http://np.archive.ubuntu.com/ > ubuntu/ trusty-updates/main libvirt0 amd64 1.2.2-0ubuntu13.1.23 [830 kB] > lxc-rtbrick-generic-17.10.1: Preconfiguring packages ... > lxc-rtbrick-generic-17.10.1: Fetched 4,664 kB in 3s (1,466 kB/s) > lxc-rtbrick-generic-17.10.1: (Reading database ... 50903 files and > directories currently installed.) > lxc-rtbrick-generic-17.10.1: Preparing to unpack > .../libidn11-dev_1.28-1ubuntu2.2_amd64.deb > ... > lxc-rtbrick-generic-17.10.1: Unpacking libidn11-dev (1.28-1ubuntu2.2) > over (1.28-1ubuntu2.1) ... > lxc-rtbrick-generic-17.10.1: Preparing to unpack > .../libidn11_1.28-1ubuntu2.2_amd64.deb ... > lxc-rtbrick-generic-17.10.1: Unpacking libidn11:amd64 > (1.28-1ubuntu2.2) over (1.28-1ubuntu2.1) ... > lxc-rtbrick-generic-17.10.1: Preparing to unpack > .../ca-certificates_20170717~14.04.1_all.deb ... > lxc-rtbrick-generic-17.10.1: Unpacking ca-certificates > (20170717~14.04.1) over (20160104ubuntu0.14.04.1) ... > lxc-rtbrick-generic-17.10.1: Preparing to unpack > .../git-man_1%3a1.9.1-1ubuntu0.7_all.deb > ... > lxc-rtbrick-generic-17.10.1: Unpacking git-man (1:1.9.1-1ubuntu0.7) > over (1:1.9.1-1ubuntu0.6) ... > lxc-rtbrick-generic-17.10.1: Preparing to unpack > .../git_1%3a1.9.1-1ubuntu0.7_amd64.deb ... > lxc-rtbrick-generic-17.10.1: Unpacking git (1:1.9.1-1ubuntu0.7) over > (1:1.9.1-1ubuntu0.6) ... > lxc-rtbrick-generic-17.10.1: Preparing to unpack > .../libvirt-dev_1.2.2-0ubuntu13.1.23_amd64.deb > ... > lxc-rtbrick-generic-17.10.1: Unpacking libvirt-dev > (1.2.2-0ubuntu13.1.23) over (1.2.2-0ubuntu13.1.22) ... > lxc-rtbrick-generic-17.10.1: Preparing to unpack > .../libvirt0_1.2.2-0ubuntu13.1.23_amd64.deb ... > lxc-rtbrick-generic-17.10.1: Unpacking libvirt0 (1.2.2-0ubuntu13.1.23) > over (1.2.2-0ubuntu13.1.22) ... > lxc-rtbrick-generic-17.10.1: Processing triggers for man-db > (2.6.7.1-1ubuntu1) ... > lxc-rtbrick-generic-17.10.1: Setting up libidn11:amd64 > (1.28-1ubuntu2.2) ... > lxc-rtbrick-generic-17.10.1: Setting up libidn11-dev (1.28-1ubuntu2.2) > ... > lxc-rtbrick-generic-17.10.1: Setting up ca-certificates > (20170717~14.04.1) ... > lxc-rtbrick-generic-17.10.1: Setting up git-man (1:1.9.1-1ubuntu0.7) > ... > lxc-rtbrick-generic-17.10.1: Setting up git (1:1.9.1-1ubuntu0.7) ... > lxc-rtbrick-generic-17.10.1: Setting up libvirt0 > (1.2.2-0ubuntu13.1.23) ... > lxc-rtbrick-generic-17.10.1: Setting up libvirt-dev > (1.2.2-0ubuntu13.1.23) ... > lxc-rtbrick-generic-17.10.1: Processing triggers for libc-bin > (2.19-0ubuntu6.13) ... > lxc-rtbrick-generic-17.10.1: Processing triggers for ca-certificates > (20170717~14.04.1) ... > lxc-rtbrick-generic-17.10.1: Updating certificates in > /etc/ssl/certs... 17 added, 42 removed; done. > lxc-rtbrick-generic-17.10.1: Running hooks in > /etc/ca-certificates/update.d....done. > lxc-rtbrick-generic-17.10.1: Reading package lists... > lxc-rtbrick-generic-17.10.1: Building dependency tree... > lxc-rtbrick-generic-17.10.1: Reading state information... > lxc-rtbrick-generic-17.10.1: The following extra packages will be > installed: > lxc-rtbrick-generic-17.10.1: linux-headers-4.4.0-53 > lxc-rtbrick-generic-17.10.1: The following NEW packages will be > installed: > lxc-rtbrick-generic-17.10.1: linux-headers-4.4.0-53 > linux-headers-4.4.0-53-generic > lxc-rtbrick-generic-17.10.1: 0 upgraded, 2 newly installed, 0 to > remove and 0 not upgraded. > lxc-rtbrick-generic-17.10.1: Need to get 10.7 MB of archives. > lxc-rtbrick-generic-17.10.1: After this operation, 87.0 MB of > additional disk space will be used. > lxc-rtbrick-generic-17.10.1: Get:1 http://np.archive.ubuntu.com/ > ubuntu/ trusty-updates/main linux-headers-4.4.0-53 all > 4.4.0-53.74~14.04.1 [9,952 kB] > lxc-rtbrick-generic-17.10.1: Get:2 http://np.archive.ubuntu.com/ > ubuntu/ trusty-updates/main linux-headers-4.4.0-53-generic amd64 > 4.4.0-53.74~14.04.1 [778 kB] > lxc-rtbrick-generic-17.10.1: Fetched 10.7 MB in 1s (5,464 kB/s) > lxc-rtbrick-generic-17.10.1: Selecting previously unselected package > linux-headers-4.4.0-53. > lxc-rtbrick-generic-17.10.1: (Reading database ... 50877 files and > directories currently installed.) > lxc-rtbrick-generic-17.10.1: Preparing to unpack > .../linux-headers-4.4.0-53_4.4.0-53.74~14.04.1_all.deb ... > lxc-rtbrick-generic-17.10.1: Unpacking linux-headers-4.4.0-53 > (4.4.0-53.74~14.04.1) ... > lxc-rtbrick-generic-17.10.1: Selecting previously unselected package > linux-headers-4.4.0-53-generic. > lxc-rtbrick-generic-17.10.1: Preparing to unpack > .../linux-headers-4.4.0-53-generic_4.4.0-53.74~14.04.1_amd64.deb ... > lxc-rtbrick-generic-17.10.1: Unpacking linux-headers-4.4.0-53-generic > (4.4.0-53.74~14.04.1) ... > lxc-rtbrick-generic-17.10.1: Setting up linux-headers-4.4.0-53 > (4.4.0-53.74~14.04.1) ... > lxc-rtbrick-generic-17.10.1: Setting up linux-headers-4.4.0-53-generic > (4.4.0-53.74~14.04.1) ... > lxc-rtbrick-generic-17.10.1: Examining /etc/kernel/header_postinst.d. > lxc-rtbrick-generic-17.10.1: run-parts: executing > /etc/kernel/header_postinst.d/dkms 4.4.0-53-generic > /boot/vmlinuz-4.4.0-53-generic > ==> lxc-rtbrick-generic-17.10.1: Provisioning with Ansible... > ==> lxc-rtbrick-generic-17.10.1: Executing Ansible: ansible-playbook > --extra-vars packer_build_name=lxc-rtbrick-generic-17.10.1 > packer_builder_type=lxc -i /tmp/packer-provisioner-ansible613077741 > rtbrick-setup-lxc-image.yaml --private-key /tmp/ansible-key758394438 > --extra-vars ansible_sudo_pass=ubuntu ansible_ssh_pass=ubuntu > lxc-rtbrick-generic-17.10.1: [DEPRECATION WARNING]: Instead of > sudo/sudo_user, use become/become_user and > lxc-rtbrick-generic-17.10.1: make sure become_method is 'sudo' > (default). > lxc-rtbrick-generic-17.10.1: This feature will be removed in a > lxc-rtbrick-generic-17.10.1: future release. Deprecation warnings can > be disabled by setting > lxc-rtbrick-generic-17.10.1: deprecation_warnings=False in ansible.cfg. > lxc-rtbrick-generic-17.10.1: > lxc-rtbrick-generic-17.10.1: PLAY [Setup the Rtbrick containers on the > host] ******************************** > lxc-rtbrick-generic-17.10.1: > lxc-rtbrick-generic-17.10.1: TASK [Gathering Facts] > ********************************************************* > ==> lxc-rtbrick-generic-17.10.1: failed to handshake > ==> lxc-rtbrick-generic-17.10.1: failed to handshake > ==> lxc-rtbrick-generic-17.10.1: failed to handshake > > > I checked to see if I could ssh with the private key and inventory file > details and faced the following issue: > > shell request failed on channel 0 > > > > Can anyone help me with the same? > > -- > This mailing list is governed under the HashiCorp Community Guidelines - > https://www.hashicorp.com/community-guidelines.html. Behavior in > violation of those guidelines may result in your removal from this mailing > list. > > GitHub Issues: https://github.com/mitchellh/packer/issues > IRC: #packer-tool on Freenode > --- > You received this message because you are subscribed to the Google Groups > "Packer" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/packer-tool/39279bc4-4453-43d4-88d5-e39e44760ee2%40googlegroups.com > <https://groups.google.com/d/msgid/packer-tool/39279bc4-4453-43d4-88d5-e39e44760ee2%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list. GitHub Issues: https://github.com/mitchellh/packer/issues IRC: #packer-tool on Freenode --- You received this message because you are subscribed to the Google Groups "Packer" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CALz9Rt_gg1asaYcMntV6AoirRT7a9H8C-fN-Ud9y%2B3TkZhka_w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
