Cannot source /etc/lsb-release

216 views
Skip to first unread message

Neil Young

unread,
Sep 27, 2021, 1:04:25 PM9/27/21
to Ansible Project
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

harry devine

unread,
Sep 27, 2021, 1:10:03 PM9/27/21
to ansible...@googlegroups.com
You should use the full path to the source executable. "which source" should give you that. 

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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fe78c00b-ac97-4960-a70b-449b0e1fcf41n%40googlegroups.com.

Sandip Bhattacharya

unread,
Sep 27, 2021, 1:11:33 PM9/27/21
to ansible...@googlegroups.com

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


HTH,
  Sandip

--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fe78c00b-ac97-4960-a70b-449b0e1fcf41n%40googlegroups.com.

Neil Young

unread,
Sep 27, 2021, 1:14:20 PM9/27/21
to Ansible Project
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...


Sandip Bhattacharya

unread,
Sep 27, 2021, 1:20:22 PM9/27/21
to ansible...@googlegroups.com
This won't work for you?

$ sudo bash -c 'source /etc/lsb-release; echo $DISTRIB_CODENAME'
focal
>> <https://groups.google.com/d/msgid/ansible-project/fe78c00b-ac97-4960-a70b-449b0e1fcf41n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> https://blog.sandipb.net <https://blog.sandipb.net>
> https://twitter.com/sandipb <https://twitter.com/sandipb>
>
> --
> 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-proje...@googlegroups.com
> <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/ac9b0dba-6437-4332-9901-2f4089e1063fn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/ac9b0dba-6437-4332-9901-2f4089e1063fn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Dick Visser

unread,
Sep 27, 2021, 1:51:58 PM9/27/21
to ansible...@googlegroups.com
On Mon, 27 Sept 2021 at 19:04, 'Neil Young' via Ansible Project
<ansible...@googlegroups.com> wrote:

> - name: Get Ubuntu version definitions
> ansible.builtin.shell: source /etc/lsb-release

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


--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Neil Young

unread,
Sep 27, 2021, 2:02:42 PM9/27/21
to Ansible Project

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

Dick Visser

unread,
Sep 27, 2021, 2:14:07 PM9/27/21
to ansible...@googlegroups.com
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






On Mon, 27 Sept 2021 at 20:02, 'Neil Young' via Ansible Project
<ansible...@googlegroups.com> wrote:
>
>
> 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
> dick....@geant.org schrieb am Montag, 27. September 2021 um 19:51:58 UTC+2:
>>
>> On Mon, 27 Sept 2021 at 19:04, 'Neil Young' via Ansible Project
>> <ansible...@googlegroups.com> wrote:
>>
>> > - name: Get Ubuntu version definitions
>> > ansible.builtin.shell: source /etc/lsb-release
>>
>> What is the purpose of this task?
>> I.e. What are you trying to achieve?
>>
>>
>> --
>> Dick Visser
>> Trust & Identity Service Operations Manager
>> GÉANT
>
> --
> 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-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ebe0ad59-57b2-46e0-9802-d9dc14adb5a9n%40googlegroups.com.

Neil Young

unread,
Sep 28, 2021, 8:33:49 AM9/28/21
to Ansible Project
This does not work for me.


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

Neil Young

unread,
Sep 28, 2021, 8:41:35 AM9/28/21
to Ansible Project
TASK [bla] ********************************************************************************************************************************************************************************************************
fatal: [server1]: FAILED! => {"changed": false, "msg": "Invalid repository string: [arch=amd64] http://ubuntu.openvidu.io/6.16.0 bionic kms6"}

Dick Visser

unread,
Sep 28, 2021, 8:49:26 AM9/28/21
to ansible...@googlegroups.com
Find out what it should be and adjust the repo value 

--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Neil Young

unread,
Sep 28, 2021, 8:51:12 AM9/28/21
to Ansible Project
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"

Neil Young

unread,
Sep 28, 2021, 8:54:42 AM9/28/21
to Ansible Project

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

Neil Young

unread,
Sep 28, 2021, 8:56:59 AM9/28/21
to Ansible Project
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.

Neil Young

unread,
Sep 28, 2021, 8:58:21 AM9/28/21
to Ansible Project
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

dulh...@mailbox.org

unread,
Oct 5, 2021, 8:20:42 AM10/5/21
to ansible...@googlegroups.com
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)?

Dick Visser

unread,
Oct 5, 2021, 8:35:30 AM10/5/21
to ansible...@googlegroups.com
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

dulh...@mailbox.org

unread,
Oct 5, 2021, 9:14:21 AM10/5/21
to ansible...@googlegroups.com
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/

Dick Visser

unread,
Oct 5, 2021, 9:56:07 AM10/5/21
to ansible...@googlegroups.com
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....
> --
> 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-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1462704195.17034.1633439638920%40office.mailbox.org.

dulh...@mailbox.org

unread,
Oct 7, 2021, 7:18:23 AM10/7/21
to ansible...@googlegroups.com

> On 10/05/2021 3:55 PM Dick Visser <dick....@geant.org> wrote:
>
> 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
Reply all
Reply to author
Forward
0 new messages