Cannot source /etc/lsb-release

Hi,

I’m banging my head trying to make this simple statement work:

  • name: Get Ubuntu version definitions

ansible.builtin.shell: source /etc/lsb-release

But whatever I do I get this:

TASK [Get Ubuntu version definitions] ****************************************************************************************************************

fatal: [server1]: FAILED! => {“changed”: true, “cmd”: “source /etc/lsb-release”, “delta”: “0:00:00.002579”, “end”: “2021-09-27 17:02:32.565396”, “msg”: “non-zero return code”, “rc”: 127, “start”: “2021-09-27 17:02:32.562817”, “stderr”: “/bin/sh: 1: source: not found”, “stderr_lines”: [“/bin/sh: 1: source: not found”], “stdout”: “”, “stdout_lines”: }

This is most likely because I run at elevated permissions.

What can I do in order to make this work?

TIA

You should use the full path to the source executable. “which source” should give you that.

Harry

source is a bash built-in command. There is no executable. You can try "bash -c ‘source /etc/lsb-release’ "

HTH,
Sandip

Exactly. which source gives nothing.

If I run the command at non-elevated level I get useful results and the environment is filled

source /etc/lsb-release

echo $DISTRIB_CODENAME

bionic

sudo source /etc/lsb-release

[sudo] password for ubuntu:

sudo: source: command not found

So it is a matter of elevated access level, but I just don’t know how to run that at lower level…

This won't work for you?

$ sudo bash -c 'source /etc/lsb-release; echo $DISTRIB_CODENAME'
focal

What is the purpose of this task?
I.e. What are you trying to achieve?

Hmm. Was posting the solution already, but it doesn’t appear here…

OK, @Sandip solved it:

  • name: Install Kurento Media Server - Get Ubuntu version definitions and add repository to apt
    ansible.builtin.shell: |
    source /etc/lsb-release
    tee “/etc/apt/sources.list.d/kurento.list” >/dev/null <<EOF

Kurento Media Server - Release packages

deb [arch=amd64] http://ubuntu.openvidu.io/6.16.0 $DISTRIB_CODENAME kms6
EOF
args:
executable: /bin/bash

Kudos to @Sandip

The information you are looking for is already available when the fact
gathering is done.
No need for kludgy shell pipes/source/tee/etc.
Also there is a dedicated module for what you want. Just 3 lines
should be enough:

- ansible.builtin.apt_repository:
    repo: "[arch=amd64] http://ubuntu.openvidu.io/6.16.0 {{
ansible_distribution_release }} kms6"
    filename: kurento

This does not work for me.

TASK [bla] ********************************************************************************************************************************************************************************************************
fatal: [server1]: FAILED! => {“changed”: false, “msg”: “Invalid repository string: [arch=amd64] http://ubuntu.openvidu.io/6.16.0 bionic kms6”}

Find out what it should be and adjust the repo value

Sorry, responded on another thread. These groups are ugly.

Well, this works:

  • name: Install Kurento Media Server - Get Ubuntu version definitions and add repository to apt
    ansible.builtin.shell: |
    source /etc/lsb-release
    tee “/etc/apt/sources.list.d/kurento.list” >/dev/null <<EOF

Kurento Media Server - Release packages

deb [arch=amd64] http://ubuntu.openvidu.io/6.16.0 $DISTRIB_CODENAME kms6
EOF
args:
executable: /bin/bash

and in the end it is just DISTRIB_CODENAME replaced by “bionic”

Seems, {{ansible_distribution_release }}} rendes “Releasebionic”, which is not ok in this case

Hmm. No. Forget about my last comment. It renders “bionic”, but even if I hardcode “bionic” the error is:

fatal: [server1]: FAILED! => {“changed”: false, “msg”: “Invalid repository string: [arch=amd64] http://ubuntu.openvidu.io/6.16.0 bionic kms6”}

Anyway, disregard please. I’m fine with the other solution.

Have it. “deb” was missing in the string:

  • name: Install Kurento Media Server
    ansible.builtin.apt_repository:
    repo: “deb [arch=amd64] http://ubuntu.openvidu.io/6.16.0 bionic kms6”
    filename: kurento

Worx

I have targets who have set a user pw to expire and I want to switch the expiration off with sudo chage -l stepuser.

this seems to work with a task like this:

  • name: switch off pw expiration for stepuser
    shell:
    cmd: chage -M -1 stepuser
    become: yes

Beind quite new to ansible I am wondering whether this is the right approach for such or anything else would be more suitable way (I can not identify any convincing paramter in the user module though)?

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html#parameter-expires
is pretty convincing to me.
See the 3rd last example on that page:

- name: Starting at Ansible 2.6, modify user, remove expiry time
  ansible.builtin.user:
    name: james18
    expires: -1

thx for the feedback

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html#parameter-expires
is pretty convincing to me.
See the 3rd last example on that page:

- name: Starting at Ansible 2.6, modify user, remove expiry time
  ansible.builtin.user:
    name: james18
    expires: -1

that sounds right, however I seem to be unable to make it work and can't really see what the problem is https://paste.debian.net/1214375/

what does your entire playbook look like? And the inventory?

I see this in the snippet:

Failed to connect to the host via ssh

that is a problem....

what does your entire playbook look like? And the inventory?

I see this in the snippet:

Failed to connect to the host via ssh

sorry, I can't exactly reconstruct what the problem was. It works now with:

- tasks:
- name: switch off pw expiration
   user:
     name: [username]
     expires: -1
   become: yes
      
thx and sorry for the false alarm
Gunnar