Re: [ansible-project] shell module with become_user does not function correctly
On Wed, 27 Sep 2023 at 22:52, 'Terry Lemons' via Ansible Project < ansible-project@googlegroups.com> wrote: > Hi - I'm having trouble using the shell module with become_user. As a > basic test, I created this playbook: > > - name: Retrieve environment variables for root > shell: printenv > > - name: Retrieve environment variables for oracle > shell: printenv > become: yes > become_user: oracle > > When I ran this with ansible-playbook and '-vvv', I noticed: > > - the output received from the first task was as expected: > > "stdout": "HOSTTYPE=x86_64\nSSH_CONNECTION=10.247.229.46 35330 > 10.247.229.191 22\nLESSCLOSE=lessclose.sh %s > %s\nXKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB\n_=/usr/bin/printenv\nLANG=POSIX\nWINDOWMANAGER=xterm\nLESS=-M > -I > -R\nHOSTNAME=ldpdd191\nCSHEDIT=emacs\nGPG_TTY=/dev/pts/0\nLESS_ADVANCED_PREPROCESSOR=no\nCOLORTERM=1\nMACHTYPE=x86_64-suse-linux\nMINICOM=-c > on\nOSTYPE=linux\nXDG_SESSION_ID=69\nUSER=root\nPAGER=less\nMORE=-sl\nPWD=/root\nHOME=/root\nLC_CTYPE=C.UTF-8\nHOST=ldpdd191\nSSH_CLIENT=10.247.229.46 > 35330 > 22\nXNLSPATH=/usr/X11R6/lib/X11/nls\nXDG_SESSION_TYPE=tty\nXDG_DATA_DIRS=/usr/share\nLIBGL_DEBUG=quiet\nPROFILEREAD=true\nSSH_TTY=/dev/pts/0\nFROM_HEADER=\nMAIL=/var/spool/mail/root\nLESSKEY=/etc/lesskey.bin\nTERM=xterm\nSHELL=/bin/bash\nXDG_SESSION_CLASS=user\nPYTHONSTARTUP=/etc/pythonstart\nSHLVL=3\nMANPATH=/usr/share/man:/usr/local/man\nLOGNAME=root\nDBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/0/bus\nXDG_RUNTIME_DIR=/run/user/0\nXDG_CONFIG_DIRS=/etc/xdg\nPATH=/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin\nG_BROKEN_FILENAMES=1\nHISTSIZE=1000\nCPU=x86_64\nSSH_SENDS_LOCALE=yes\nLESSOPEN=lessopen.sh > %s", > > but the output received from the second task (which uses 'become_user') > was not correct: > > "stdout": > "_=/usr/bin/printenv\nLANG=POSIX\nSUDO_GID=0\nCOLORTERM=1\nSUDO_COMMAND=/bin/sh > -c echo BECOME-SUCCESS-ukrwuqlueafnghzqqoabhpfcwxwpieyw ; > /usr/bin/python3.6 > /var/tmp/ansible-tmp-1695847065.2341652-30706-3263662880779/AnsiballZ_command.py\nUSER=oracle\nPWD=/home/oracle/.ansible/tmp/ansible-moduletmp-1695847065.5976799-u8hbo4o2\nHOME=/home/oracle\nLC_CTYPE=C.UTF-8\nSUDO_USER=root\nSUDO_UID=0\nMAIL=/var/mail/oracle\nTERM=xterm\nSHELL=/bin/bash\nSHLVL=2\nLOGNAME=oracle\nPATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin:/usr/local/sbin", > > so, it seem that using 'become_user' perverts the function of the 'shell' > module, and the command provided is not executed as expected. > What do you expect? And what do you mean by "perverts the function"? Because it seems to work fine to me. -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAF8BbLbMQQCDmq3V7v35fpruLcfv-3-Gc5NZp1oHN4KTYiTq%3Dw%40mail.gmail.com.
[ansible-project] shell module with become_user does not function correctly
Hi - I'm having trouble using the shell module with become_user. As a basic test, I created this playbook: - name: Retrieve environment variables for root shell: printenv - name: Retrieve environment variables for oracle shell: printenv become: yes become_user: oracle When I ran this with ansible-playbook and '-vvv', I noticed: - the output received from the first task was as expected: "stdout": "HOSTTYPE=x86_64\nSSH_CONNECTION=10.247.229.46 35330 10.247.229.191 22\nLESSCLOSE=lessclose.sh %s %s\nXKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB\n_=/usr/bin/printenv\nLANG=POSIX\nWINDOWMANAGER=xterm\nLESS=-M -I -R\nHOSTNAME=ldpdd191\nCSHEDIT=emacs\nGPG_TTY=/dev/pts/0\nLESS_ADVANCED_PREPROCESSOR=no\nCOLORTERM=1\nMACHTYPE=x86_64-suse-linux\nMINICOM=-c on\nOSTYPE=linux\nXDG_SESSION_ID=69\nUSER=root\nPAGER=less\nMORE=-sl\nPWD=/root\nHOME=/root\nLC_CTYPE=C.UTF-8\nHOST=ldpdd191\nSSH_CLIENT=10.247.229.46 35330 22\nXNLSPATH=/usr/X11R6/lib/X11/nls\nXDG_SESSION_TYPE=tty\nXDG_DATA_DIRS=/usr/share\nLIBGL_DEBUG=quiet\nPROFILEREAD=true\nSSH_TTY=/dev/pts/0\nFROM_HEADER=\nMAIL=/var/spool/mail/root\nLESSKEY=/etc/lesskey.bin\nTERM=xterm\nSHELL=/bin/bash\nXDG_SESSION_CLASS=user\nPYTHONSTARTUP=/etc/pythonstart\nSHLVL=3\nMANPATH=/usr/share/man:/usr/local/man\nLOGNAME=root\nDBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/0/bus\nXDG_RUNTIME_DIR=/run/user/0\nXDG_CONFIG_DIRS=/etc/xdg\nPATH=/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin\nG_BROKEN_FILENAMES=1\nHISTSIZE=1000\nCPU=x86_64\nSSH_SENDS_LOCALE=yes\nLESSOPEN=lessopen.sh %s", but the output received from the second task (which uses 'become_user') was not correct: "stdout": "_=/usr/bin/printenv\nLANG=POSIX\nSUDO_GID=0\nCOLORTERM=1\nSUDO_COMMAND=/bin/sh -c echo BECOME-SUCCESS-ukrwuqlueafnghzqqoabhpfcwxwpieyw ; /usr/bin/python3.6 /var/tmp/ansible-tmp-1695847065.2341652-30706-3263662880779/AnsiballZ_command.py\nUSER=oracle\nPWD=/home/oracle/.ansible/tmp/ansible-moduletmp-1695847065.5976799-u8hbo4o2\nHOME=/home/oracle\nLC_CTYPE=C.UTF-8\nSUDO_USER=root\nSUDO_UID=0\nMAIL=/var/mail/oracle\nTERM=xterm\nSHELL=/bin/bash\nSHLVL=2\nLOGNAME=oracle\nPATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin:/usr/local/sbin", so, it seem that using 'become_user' perverts the function of the 'shell' module, and the command provided is not executed as expected. Is this a known bug/limitation? Thanks! tl -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1bf473a0-6bd1-4f5f-99d2-b23b388e0e29n%40googlegroups.com.
Re: [ansible-project] Retrieving items from a dictionary
Map the attribute dn: "{{ ansible_mounts| selectattr('device', 'contains', 'nas-server.example.com')| map(attribute='device') }}" If you want to skip empty lists test the length - debug: var: dn when: dn|length > 0 -- Vladimir Botka -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20230927213245.3f39b2f8%40gmail.com. pgpHL7pnDuN1i.pgp Description: OpenPGP digital signature
[ansible-project] Retrieving items from a dictionary
I am trying to look at our server mounts and only show those that have a specific mount available. The playbook is as follows: --- - hosts: all_hosts become: true become_method: sudo gather_facts: true tasks: - name: Get mount points ansible.builtin.set_fact: device_names: "{{ ansible_mounts | selectattr('device', 'contains', 'nas-server.example.com') | list }}" - name: List servers with those mount points ansible.builtin.debug: msg: "{{ device_names }}" I have 2 small issues with the output: 1) The device_names shows everything about that mount and I only want to show the device attribute; 2) Hosts that do not have the mount present show up in my debug list with an empty string. I'd like to not show them at all if possible. ok: [server1.example.com] => { "msg": [ { "block_available": 26201799211, "block_size": 4096, "block_total": 36234081792, "block_used": 10032282581, "device": "nas-server.example.com:/projects", "fstype": "fuse.glusterfs", "inode_available": 14493376449, "inode_total": 14495510592, "inode_used": 2134143, "mount": "/projects", "options": "rw,nodev,relatime,user_id=0,group_id=0,allow_other,max_read=131072", "size_available": 107322569568256, "size_total": 148414799020032, "uuid": "N/A" } ] } ok: [server2.example.com] => { "msg": [] } Thanks for any help, Harry -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b724b0c0-93e7-4516-b839-73dd7141cb94n%40googlegroups.com.