Neil_Young
(Neil Young)
September 27, 2021, 5:04pm
1
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
Neil_Young
(Neil Young)
September 27, 2021, 5:14pm
4
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?
Neil_Young
(Neil Young)
September 27, 2021, 6:02pm
7
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
Neil_Young
(Neil Young)
September 28, 2021, 12:33pm
9
This does not work for me.
Neil_Young
(Neil Young)
September 28, 2021, 12:41pm
10
TASK [bla] ********************************************************************************************************************************************************************************************************
fatal: [server1]: FAILED! => {“changed”: false, “msg”: “Invalid repository string: [arch=amd64] http://ubuntu.openvidu.io/6.16.0 bionic kms6”}
Dick_Visser
(Dick Visser)
September 28, 2021, 12:49pm
11
Find out what it should be and adjust the repo value
Neil_Young
(Neil Young)
September 28, 2021, 12:51pm
12
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
(Neil Young)
September 28, 2021, 12:54pm
13
Seems, {{ansible_distribution_release }}} rendes “Releasebionic”, which is not ok in this case
Neil_Young
(Neil Young)
September 28, 2021, 12:56pm
14
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
(Neil Young)
September 28, 2021, 12:58pm
15
Have it. “deb” was missing in the string:
Worx
dulhaver
(Gunnar)
October 5, 2021, 12:20pm
16
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
dulhaver
(Gunnar)
October 5, 2021, 1:13pm
18
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....
dulhaver
(Gunnar)
October 7, 2021, 11:18am
20
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