#355 Local testing fails when adding standard-test-source to tests.yml
Closed: SOLVED 4 years ago by bgoncalv. Opened 4 years ago by gicmo.

I have a very simple tests.yml:

---
- hosts: localhost
  roles:
  - role: standard-test-source
    tags:
    - always
  - role: standard-test-basic
    tags:
    - classic
    required_packages:
    - bolt
    tests:
    - smoke:
        dir: smoke
        run: boltctl --version
    - integration:
        dir: ./source/tests/
        run: ./test-integration

I am trying to test it locally, in a F30 VM (cloud image), provisioned with users root and gicmo) that can be reached via ssh as vm (gicmo user) and vm-root (root user).

I am using a ansible inventory file ci.ini:

[localhost]
sut ansible_host=vm ansible_python_interpreter=/usr/bin/python3

When connecting to the VM with the normal user (ansible_host=vm), I get the following error message:

fatal: [sut]: FAILED! => {"msg": "The conditional check 'rpm_result.failed == true' failed. The error was: error while evaluating conditional (rpm_result.failed == true): 'dict object' has no attribute 'failed'\n\nThe error appears to be in '/usr/share/ansible/roles/standard-test-source/tasks/main.yml': line 47, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - fail:\n      ^ here\n"}

When connecting to the VM with the root user (ansible_host=vm-root), I get the following error message:

failed: [sut] (item=rpm-build) => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "ansible_loop_var": "item", "attempts": 5, "changed": false, "cmd": "dnf install -y python2-dnf", "item": "rpm-build", "msg": "Error: This command has to be run under the root user.", "rc": 1, "stderr": "Error: This command has to be run under the root user.\n", "stderr_lines": ["Error: This command has to be run under the root user."], "stdout": "", "stdout_lines": []}

Version info:

rpm -qi standard-test-roles 
Name        : standard-test-roles
Version     : 4.0
Release     : 1.module_f30+4283+a656bc68

rpm -qi ansible
Name        : ansible
Version     : 2.8.0
Release     : 2.fc30

→ ansible-playbook -i ../../ci.ini --tags=classic tests.yml -v                                         [ci | M2 A1] 
Using /etc/ansible/ansible.cfg as config file

PLAY [localhost] *******************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************
ok: [sut] => {"ansible_facts": {"ansible_all_ipv4_addresses": ["10.0.2.15"], "ansible_all_ipv6_addresses": ["fec0::5054:ff:fe12:3456", "fe80::5054:ff:fe12:3456"], "ansible_apparmor": {"status": "disabled"}, "ansible_architecture": "x86_64", "ansible_bios_date": "04/01/2014", "ansible_bios_version": "1.12.0-2.fc30", "ansible_cmdline": {"BOOT_IMAGE": "(hd0,msdos1)/boot/vmlinuz-5.0.0-300.fc30.x86_64", "console": "ttyS0,115200n8", "net.ifnames": "0", "no_timer_check": true, "ro": true, "root": "UUID=d638b533-484a-4ab3-bd86-728c9ab6a610"}, "ansible_date_time": {"date": "2019-05-28", "day": "28", "epoch": "1559055415", "hour": "14", "iso8601": "2019-05-28T14:56:55Z", "iso8601_basic": "20190528T145655044445", "iso8601_basic_short": "20190528T145655", "iso8601_micro": "2019-05-28T14:56:55.044698Z", "minute": "56", "month": "05", "second": "55", "time": "14:56:55", "tz": "UTC", "tz_offset": "+0000", "weekday": "Tuesday", "weekday_number": "2", "weeknumber": "21", "year": "2019"}, "ansible_default_ipv4": {"address": "10.0.2.15", "alias": "eth0", "broadcast": "10.0.2.255", "gateway": "10.0.2.2", "interface": "eth0", "macaddress": "52:54:00:12:34:56", "mtu": 1500, "netmask": "255.255.255.0", "network": "10.0.2.0", "type": "ether"}, "ansible_default_ipv6": {"address": "fec0::5054:ff:fe12:3456", "gateway": "fe80::2", "interface": "eth0", "macaddress": "52:54:00:12:34:56", "mtu": 1500, "prefix": "64", "scope": "site", "type": "ether"}, "ansible_device_links": {"ids": {"sda": ["ata-QEMU_HARDDISK_QM00001"], "sda1": ["ata-QEMU_HARDDISK_QM00001-part1"], "sr0": ["ata-QEMU_DVD-ROM_QM00003"]}, "labels": {"sr0": ["cidata"]}, "masters": {}, "uuids": {"sda1": ["d638b533-484a-4ab3-bd86-728c9ab6a610"], "sr0": ["2019-05-28-15-34-06-00"]}}, "ansible_devices": {"sda": {"holders": [], "host": "", "links": {"ids": ["ata-QEMU_HARDDISK_QM00001"], "labels": [], "masters": [], "uuids": []}, "model": "QEMU HARDDISK", "partitions": {"sda1": {"holders": [], "links": {"ids": ["ata-QEMU_HARDDISK_QM00001-part1"], "labels": [], "masters": [], "uuids": ["d638b533-484a-4ab3-bd86-728c9ab6a610"]}, "sectors": "8386560", "sectorsize": 512, "size": "4.00 GB", "start": "2048", "uuid": "d638b533-484a-4ab3-bd86-728c9ab6a610"}}, "removable": "0", "rotational": "1", "sas_address": null, "sas_device_handle": null, "scheduler_mode": "mq-deadline", "sectors": "8388608", "sectorsize": "512", "size": "4.00 GB", "support_discard": "512", "vendor": "ATA", "virtual": 1}, "sr0": {"holders": [], "host": "", "links": {"ids": ["ata-QEMU_DVD-ROM_QM00003"], "labels": ["cidata"], "masters": [], "uuids": ["2019-05-28-15-34-06-00"]}, "model": "QEMU DVD-ROM", "partitions": {}, "removable": "1", "rotational": "1", "sas_address": null, "sas_device_handle": null, "scheduler_mode": "mq-deadline", "sectors": "732", "sectorsize": "2048", "size": "366.00 KB", "support_discard": "0", "vendor": "QEMU", "virtual": 1}}, "ansible_distribution": "Fedora", "ansible_distribution_file_parsed": true, "ansible_distribution_file_path": "/etc/redhat-release", "ansible_distribution_file_variety": "RedHat", "ansible_distribution_major_version": "30", "ansible_distribution_release": "", "ansible_distribution_version": "30", "ansible_dns": {"nameservers": ["10.0.2.3"]}, "ansible_domain": "", "ansible_effective_group_id": 1000, "ansible_effective_user_id": 1000, "ansible_env": {"DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus", "HOME": "/home/gicmo", "LANG": "en_GB.UTF-8", "LESSOPEN": "||/usr/bin/lesspipe.sh %s", "LOGNAME": "gicmo", "LS_COLORS": "rs=0:di=38;5;33:ln=38;5;51:mh=00:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=01;05;37;41:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;40:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lz4=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.zst=38;5;9:*.tzst=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.wim=38;5;9:*.swm=38;5;9:*.dwm=38;5;9:*.esd=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.mjpg=38;5;13:*.mjpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.webm=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.m4a=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.oga=38;5;45:*.opus=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:", "MAIL": "/var/mail/gicmo", "PATH": "/home/gicmo/.local/bin:/home/gicmo/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin", "PWD": "/home/gicmo", "SELINUX_LEVEL_REQUESTED": "", "SELINUX_ROLE_REQUESTED": "", "SELINUX_USE_CURRENT_RANGE": "", "SHELL": "/bin/bash", "SHLVL": "1", "SSH_AUTH_SOCK": "/tmp/ssh-pTIjC5rHz5/agent.2137", "SSH_CLIENT": "10.0.2.2 44206 22", "SSH_CONNECTION": "10.0.2.2 44206 10.0.2.15 22", "SSH_TTY": "/dev/pts/1", "TERM": "xterm-256color", "USER": "gicmo", "XDG_RUNTIME_DIR": "/run/user/1000", "XDG_SESSION_CLASS": "user", "XDG_SESSION_ID": "24", "XDG_SESSION_TYPE": "tty", "XMODIFIERS": "@im=ibus", "_": "/usr/bin/python3"}, "ansible_eth0": {"active": true, "device": "eth0", "ipv4": {"address": "10.0.2.15", "broadcast": "10.0.2.255", "netmask": "255.255.255.0", "network": "10.0.2.0"}, "ipv6": [{"address": "fec0::5054:ff:fe12:3456", "prefix": "64", "scope": "site"}, {"address": "fe80::5054:ff:fe12:3456", "prefix": "64", "scope": "link"}], "macaddress": "52:54:00:12:34:56", "module": "virtio_net", "mtu": 1500, "pciid": "virtio0", "promisc": false, "speed": -1, "type": "ether"}, "ansible_fibre_channel_wwn": [], "ansible_fips": false, "ansible_form_factor": "Other", "ansible_fqdn": "vm", "ansible_hostname": "vm", "ansible_hostnqn": "", "ansible_interfaces": ["lo", "eth0"], "ansible_is_chroot": false, "ansible_iscsi_iqn": "", "ansible_kernel": "5.0.0-300.fc30.x86_64", "ansible_lo": {"active": true, "device": "lo", "ipv4": {"address": "127.0.0.1", "broadcast": "host", "netmask": "255.0.0.0", "network": "127.0.0.0"}, "ipv6": [{"address": "::1", "prefix": "128", "scope": "host"}], "mtu": 65536, "promisc": false, "type": "loopback"}, "ansible_local": {}, "ansible_lsb": {}, "ansible_machine": "x86_64", "ansible_machine_id": "c2e97a5f4f8e4c45a88ff2ad36212a3e", "ansible_memfree_mb": 1406, "ansible_memory_mb": {"nocache": {"free": 1855, "used": 135}, "real": {"free": 1406, "total": 1990, "used": 584}, "swap": {"cached": 0, "free": 0, "total": 0, "used": 0}}, "ansible_memtotal_mb": 1990, "ansible_mounts": [{"block_available": 674448, "block_size": 4096, "block_total": 1015472, "block_used": 341024, "device": "/dev/sda1", "fstype": "ext4", "inode_available": 233548, "inode_total": 262144, "inode_used": 28596, "mount": "/", "options": "rw,seclabel,relatime", "size_available": 2762539008, "size_total": 4159373312, "uuid": "d638b533-484a-4ab3-bd86-728c9ab6a610"}], "ansible_nodename": "vm", "ansible_os_family": "RedHat", "ansible_pkg_mgr": "dnf", "ansible_proc_cmdline": {"BOOT_IMAGE": "(hd0,msdos1)/boot/vmlinuz-5.0.0-300.fc30.x86_64", "console": ["tty1", "ttyS0,115200n8"], "net.ifnames": "0", "no_timer_check": true, "ro": true, "root": "UUID=d638b533-484a-4ab3-bd86-728c9ab6a610"}, "ansible_processor": ["0", "GenuineIntel", "QEMU Virtual CPU version 2.5+"], "ansible_processor_cores": 1, "ansible_processor_count": 1, "ansible_processor_threads_per_core": 1, "ansible_processor_vcpus": 1, "ansible_product_name": "Standard PC (i440FX + PIIX, 1996)", "ansible_product_serial": "NA", "ansible_product_uuid": "NA", "ansible_product_version": "pc-i440fx-3.1", "ansible_python": {"executable": "/usr/bin/python3", "has_sslcontext": true, "type": "cpython", "version": {"major": 3, "micro": 2, "minor": 7, "releaselevel": "final", "serial": 0}, "version_info": [3, 7, 2, "final", 0]}, "ansible_python_version": "3.7.2", "ansible_real_group_id": 1000, "ansible_real_user_id": 1000, "ansible_selinux": {"config_mode": "enforcing", "mode": "enforcing", "policyvers": 31, "status": "enabled", "type": "targeted"}, "ansible_selinux_python_present": true, "ansible_service_mgr": "systemd", "ansible_ssh_host_key_ecdsa_public": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCCH1c6A10ojrBGT7TdAN10jsaVwa5oKZWHk8rLXWpDesd4Q1mA5XCHPOV2y3mxp/ccAynE579JAO9AkTmiaL6o=", "ansible_ssh_host_key_ed25519_public": "AAAAC3NzaC1lZDI1NTE5AAAAIAXHDsD0CRKgGTDgYXeQlzdn8dReYIHo7oc+JBaGIT6A", "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAADAQABAAABAQCpXPt1OsptEzoDIBDHFBfzZzd9SmaMD4t9Gp+dxkGvYQR9ylaTGAALMzoAen6WZwpEjreL2yaBO/X1sX7d7NvNIaAVkKlChggX0Pug/0e5Fq2hE5YHzVsZ9odjRT/uZSndCi4YYtD5XD/DExsqczk4EnNl7/OVZCir/eRKwOSdHRKTq42khNTTvZK1vvpsLtScObseNyhLWN88qEEPh9UPq/SCFOsCuTbMA3IGD8sE53K3VNjJJmd9owiLTbWoYmpR/oW+OEvbLIx+ZmttNAOdCG9W3PVzgl7XaZAukCpt0GkE0FP+Lat17h1gOmGAflTq/W5YiMXrcKl2Xeg5uOVv", "ansible_swapfree_mb": 0, "ansible_swaptotal_mb": 0, "ansible_system": "Linux", "ansible_system_capabilities": [""], "ansible_system_capabilities_enforced": "True", "ansible_system_vendor": "QEMU", "ansible_uptime_seconds": 4961, "ansible_user_dir": "/home/gicmo", "ansible_user_gecos": "CK", "ansible_user_gid": 1000, "ansible_user_id": "gicmo", "ansible_user_shell": "/bin/bash", "ansible_user_uid": 1000, "ansible_userspace_architecture": "x86_64", "ansible_userspace_bits": "64", "ansible_virtualization_role": "guest", "ansible_virtualization_type": "kvm", "gather_subset": ["all"], "module_setup": true}, "changed": false}

TASK [standard-test-source : Add executor host] ************************************************************************************
changed: [sut] => {"add_host": {"groups": [], "host_name": "executor", "host_vars": {"ansible_connection": "local", "ansible_host": "127.0.0.1", "ansible_ssh_connection": "local"}}, "changed": true}

TASK [standard-test-source : Set ansible_python_interpreter to /usr/bin/python3] ***************************************************
skipping: [sut] => {"changed": false, "skip_reason": "Conditional result was False"}

TASK [standard-test-source : Gather facts] *****************************************************************************************
[DEPRECATION WARNING]: Distribution fedora 30 on host sut should use /usr/bin/python3, but is using /usr/bin/python for backward 
compatibility with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this 
host. See https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html for more information. This feature 
will be removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
ok: [sut]

TASK [standard-test-source : Install basic package dependencies] *******************************************************************
skipping: [sut] => (item=rpm-build)  => {"ansible_loop_var": "item", "changed": false, "item": "rpm-build", "skip_reason": "Conditional result was False"}

TASK [standard-test-source : Check if required packages are installed on the system] ***********************************************
changed: [sut] => (item=rpm-build) => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "ansible_loop_var": "item", "changed": true, "cmd": ["rpm", "-q", "rpm-build"], "delta": "0:00:00.008080", "deprecations": [{"msg": "Distribution fedora 30 on host sut should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html for more information", "version": "2.12"}], "end": "2019-05-28 16:56:56.270026", "item": "rpm-build", "rc": 0, "start": "2019-05-28 16:56:56.261946", "stderr": "", "stderr_lines": [], "stdout": "rpm-build-4.14.2.1-4.fc30.1.x86_64", "stdout_lines": ["rpm-build-4.14.2.1-4.fc30.1.x86_64"], "warnings": ["Consider using the yum, dnf or zypper module rather than running 'rpm'.  If you need to use command because yum, dnf or zypper is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message."]}
 [WARNING]: Consider using the yum, dnf or zypper module rather than running 'rpm'.  If you need to use command because yum, dnf or
zypper is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of
this message.


TASK [standard-test-source : fail] *************************************************************************************************
fatal: [sut]: FAILED! => {"msg": "The conditional check 'rpm_result.failed == true' failed. The error was: error while evaluating conditional (rpm_result.failed == true): 'dict object' has no attribute 'failed'\n\nThe error appears to be in '/usr/share/ansible/roles/standard-test-source/tasks/main.yml': line 47, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - fail:\n      ^ here\n"}

PLAY RECAP *************************************************************************************************************************
sut                        : ok=4    changed=2    unreachable=0    failed=1    skipped=2    rescued=0    ignored=0 

it seems there is a problem checking what user is running the playbook if we set root user in the inventory.

I've created a new PR that doesn't check for user any more, and only tries to install package if package is not installed yet.

https://pagure.io/standard-test-roles/pull-request/357

This is the copr build for the PR: https://copr.fedorainfracloud.org/coprs/g/osci/standard-test-roles/build/916564/

@bgoncalv it indeed fixes the issue for me. \o/ Thanks so much!

PLAY RECAP ****************************************************************************************
sut                        : ok=53   changed=16   unreachable=0    failed=0    skipped=16   rescued=0    ignored=0

Metadata Update from @bgoncalv:
- Issue close_status updated to: SOLVED
- Issue status updated to: Closed (was: Open)

4 years ago

Login to comment on this ticket.

Metadata