Seeking advice on converting bash oneliners into ansible
Trying to install the latest glpi-agent on workstations
This the code in bash that works, when run as root
#!/bin/bash
# ensure that perl en curl are installed
apt install perl curl -y
#there is no "latest" script and no repository, this method is approved in the git notes request by the developers to retrieve the current version
export TAG=`curl -s https://api.github.com/repos/glpi-project/glpi-agent/releases/latest | grep tag_name | cut -d \" -f 4`
#downloading the current script based on the $TAG version retrieved from the webpage
wget https://github.com/glpi-project/glpi-agent/releases/download/$TAG/glpi-agent-$TAG-linux-installer.pl
#install the agent
perl ./glpi-agent-$TAG-linux-installer.pl -s https://inventory.domain.com/
#run the agent
glpi-agent
or as oneliner:
apt install perl curl -y && export TAG=`curl -s https://api.github.com/repos/glpi-project/glpi-agent/releases/latest | grep tag_name | cut -d \" -f 4` && wget https://github.com/glpi-project/glpi-agent/releases/download/$TAG/glpi-agent-$TAG-linux-installer.pl && sudo perl ./glpi-agent-$TAG-linux-installer.pl -s https://inventory.domain.com/ && glpi-agent
Question: how to let this run on a range of systems like defined in /etc/ansible/hosts: blunt or best practice, are all fine,
Maybe someone made already an ansible “glpi-agent_install” with “ensure latest”?
ansible cli can retrieve the $TAG, if I escape the ""
first one doesnt work
ansible testhost -m shell -a "curl -s https://api.github.com/repos/glpi-project/glpi-agent/releases/latest | grep tag_name | c
ut -d \" -f 4"
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020,
16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by
setting deprecation_warnings=False in ansible.cfg.
ERROR! failed at splitting arguments, either an unbalanced jinja2 block or quotes: curl -s https://api.github.com/repos/glpi-project/glpi-agent/releases/late
st | grep tag_name | cut -d " -f 4
but second is fine
ansible testhost -m shell -a "curl -s https://api.github.com/repos/glpi-project/glpi-agent/releases/latest | grep tag_name | c
ut -d \\\" -f 4"
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020,
16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by
setting deprecation_warnings=False in ansible.cfg.
testhost | CHANGED | rc=0 >>
1.10
Reusing that value in a variable appears problematic:
[ansible-user@ansible-server ansible]$ ansible opti-014 -m shell -a "TAG=`curl -s https://api.github.com/repos/glpi-project/glpi-agent/releases/latest | grep tag_name | cut -d \\\" -f 4`"
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020,
16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by
setting deprecation_warnings=False in ansible.cfg.
opti-014 | CHANGED | rc=0 >>
[ansibleuser@ansible-server ansible]$ ansible opti-014 -m shell -a "echo $TAG"
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020,
16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by
setting deprecation_warnings=False in ansible.cfg.
opti-014 | CHANGED | rc=0 >>
[ansible-user@ansible-server ansible]$ ansible opti-014 -m shell -a "TAG=`curl -s https://api.github.com/repos/glpi-project/glpi-agent/releases/latest | grep tag_nam
e | cut -d \\\" -f 4` && echo $TAG"
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020,
16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by
setting deprecation_warnings=False in ansible.cfg.
opti-014 | CHANGED | rc=0 >>
[ansible-user@ansible-server ansible]$
BTW: I used this ansible a lot in CLI mode for ansible one-liners, very usefull.
Even though it is old, I think that the old version of ansible is not the issue.
Anyway I will shedule a new install of ansible on a current debian 12, to see if that works better
BBTW: I was reading the “facts” section of playbooks, but I didn’t get to a solution yet, not sure if it will help.