Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade from 2.3 to 2.4 breaks vars loading when using 'path' as inventory_hostname #32764

Closed
ksmets opened this issue Nov 9, 2017 · 3 comments · Fixed by #32778
Closed

upgrade from 2.3 to 2.4 breaks vars loading when using 'path' as inventory_hostname #32764

ksmets opened this issue Nov 9, 2017 · 3 comments · Fixed by #32778
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@ksmets
Copy link

ksmets commented Nov 9, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

chroot

ANSIBLE VERSION
ansible 2.4.1.0
  config file = /home/ksmets/my-ansible-playbooks/ansible.cfg
  configured module search path = [u'/home/ksmets/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ksmets/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible
  executable location = /home/ksmets/.virtualenvs/ansible/bin/ansible
  python version = 2.7.11+ (default, Apr 17 2016, 14:00:29) [GCC 5.3.1 20160413]
CONFIGURATION
OS / ENVIRONMENT
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"
Linux midgard 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
SUMMARY

After upgrading from a 2.3-release (i.e. 2.3.2.0) to the latest 2.4-release (i.e. 2.4.1.0) the chroot connection plugin no longer works.

STEPS TO REPRODUCE
---
# file: build-rpi-sd-card.yml

- hosts: localhost
  vars:
    rasbian_version: 2017-09-07-raspbian-stretch-lite
    rasbian_mountpoint: /mnt/rpi
  pre_tasks:
  - name: install required packages
    apt:
      name: "{{ item }}"
      state: present
    with_items:
    - qemu
    - qemu-user-static
    - binfmt-support
  tasks:
  - name: download rasbian
    get_url:
      url: http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-09-08/{{ rasbian_version }}.zip
      dest: ~/Downloads/{{ rasbian_version }}.zip

  - name: extract rasbian image
    unarchive:
      src: ~/Downloads/{{ rasbian_version }}.zip
      dest: /dev/shm
      creates: /dev/shm/{{ rasbian_version }}.img

  - name: get the name of the first unused loop device
    command: losetup --find
    register: result
    changed_when: False

  - name: register the name of the first unused loop device
    set_fact:
      loopdev: "{{ result.stdout }}"

  - name: set up the loop device
    command: losetup --partscan {{ loopdev }} /dev/shm/{{ rasbian_version }}.img creates={{ loopdev }}p*

  - name: ensure the mount point exists
    file:
      path: "{{ rasbian_mountpoint }}"
      state: directory

  - name: mount the root partition
    command: mount {{ loopdev }}p2 {{ rasbian_mountpoint }} creates={{ rasbian_mountpoint }}/boot warn=no

  - name: mount the boot partition
    command: mount {{ loopdev }}p1 {{ rasbian_mountpoint }}/boot creates={{ rasbian_mountpoint }}/boot/kernel.img warn=no

  - name: copy qemu-arm-static
    copy:
      src: /usr/bin/qemu-arm-static
      dest: "{{ rasbian_mountpoint }}/usr/bin/qemu-arm-static"
      mode: 0755

  - name: comment line in /etc/ld.so.preload
    lineinfile:
      path: "{{ rasbian_mountpoint }}/etc/ld.so.preload"
      regexp: '/usr/lib/arm-linux-gnueabihf/libarmmem.so'
      line: '#/usr/lib/arm-linux-gnueabihf/libarmmem.so'

  - name: add {{ rasbian_mountpoint }} to chroots group
    add_host:
      name: "{{ rasbian_mountpoint }}"
      groups: chroots

- hosts: chroots
  connection: chroot
  tasks:
  - ping:

- hosts: localhost
  vars:
    rasbian_mountpoint: /mnt/rpi
  tasks:
  - name: uncomment line in /etc/ld.so.preload
    lineinfile:
      path: "{{ rasbian_mountpoint }}/etc/ld.so.preload"
      regexp: '#/usr/lib/arm-linux-gnueabihf/libarmmem.so'
      line: '/usr/lib/arm-linux-gnueabihf/libarmmem.so'

  - name: remove qemu-arm-static
    file:
      path: "{{ rasbian_mountpoint }}/usr/bin/qemu-arm-static"
      state: absent

  - name: unmount the boot partition
    command: umount {{ rasbian_mountpoint }}/boot removes={{ rasbian_mountpoint }}/boot/kernel.img

  - name: unmount the root partition
    command: umount {{ rasbian_mountpoint }} removes={{ rasbian_mountpoint }}/boot

  - name: ensure the mount point doesn't exist
    file:
      path: "{{ rasbian_mountpoint }}"
      state: absent

  - name: detach the loop device
    command: losetup --detach {{ loopdev }} removes={{ loopdev }}p*
EXPECTED RESULTS
sudo ansible -c chroot -i /mnt/rpi, -m ping all
/mnt/rpi | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
ACTUAL RESULTS
sudo ansible -c chroot -i /mnt/rpi, -m ping all -vvvv

ansible 2.4.1.0
  config file = /home/ksmets/my-ansible-playbooks/ansible.cfg
  configured module search path = [u'/home/ksmets/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ksmets/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible
  executable location = /home/ksmets/.virtualenvs/ansible/bin/ansible
  python version = 2.7.11+ (default, Apr 17 2016, 14:00:29) [GCC 5.3.1 20160413]
Using /home/ksmets/my-ansible-playbooks/ansible.cfg as config file
setting up inventory plugins
Unable to parse address from hostname, leaving unchanged: Not a valid network hostname: /mnt/rpi
Parsed /mnt/rpi, inventory source with host_list plugin
Loading callback plugin minimal of type stdout, v2.0 from /home/ksmets/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
META: ran handlers
ERROR! Syntax Error while loading YAML.


The error appears to have been in '/mnt/rpi/etc/dhcp/debug': line 12, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

if [ "$RUN" = "yes" ]; then
	echo "$(date): entering ${1%/*}, dumping variables." \
^ here
There appears to be a tab character at the start of the line.

YAML does not use tabs for formatting. Tabs should be replaced with spaces.

For example:
    - name: update tooling
      vars:
        version: 1.2.3
#    ^--- there is a tab there.

Should be written as:
    - name: update tooling
      vars:
        version: 1.2.3
# ^--- all spaces here.

exception type: <class 'yaml.scanner.ScannerError'>
exception: while scanning for the next token
found character '\t' that cannot start any token
  in "<unicode string>", line 12, column 1:
    	echo "$(date): entering ${1%/*} ... 
    ^
@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Nov 9, 2017
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Nov 10, 2017
@bcoca
Copy link
Member

bcoca commented Nov 10, 2017

its not the chroot plugin that breaks here, its 'host_vars loading' as the inventory hostname is valid path and the vars plugin finds a file but it fails to parse it.

This should workaround it for now:

ansible -c chroot -i rpi_host, -m ping all -e 'ansible_host=/mnt/rpi

@bcoca bcoca changed the title upgrade from 2.3 to 2.4 breaks chroot connection plugin upgrade from 2.3 to 2.4 breaks vars loading when using 'path' as inventory_hostname Nov 10, 2017
bcoca added a commit to bcoca/ansible that referenced this issue Nov 10, 2017
@bcoca
Copy link
Member

bcoca commented Nov 10, 2017

@ksmets please confirm that the PR above resolves the issue for you

@ksmets
Copy link
Author

ksmets commented Nov 10, 2017

Thx @bcoca, PR #32778 fixes this problem.

bcoca added a commit that referenced this issue Nov 10, 2017
* avoid chroot paths in entity names when loading host_group_vars

fixes #32764

(cherry picked from commit e7941b0)
bcoca added a commit that referenced this issue Nov 10, 2017
* avoid chroot paths

fixes #32764

* check name
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants