Hello,
I am trying to get the latest version of few softwares and comparing it
with a list of hosts with the current installed.
Calling the github API is creating issues with the number of call due to
the the list of hosts that is quite big.
So I would like to register the latest versions in a variable and then use
it to compare for each host.
I tried a lot of things, like run_once, changed_when but it seems like it
is not working.
Here is the playbook.
- hosts: "{{ variable_host }}"
serial: 1
tasks:
-
name: "Get PHP version from site"
register: PHP_SITE_RESPONSE
uri:
body_format: json
method: GET
return_content: true
url: "https://www.php.net/releases/?json&version=7.2"
run_once: true
delegate_to: 127.0.0.1
-
name: "Get APACHE version from site"
shell: "curl -s
'https://api.github.com/repos/apache/httpd/tags?per_page=100' | jq -r '.[]
| .name' | sort -V | grep ^2.4 | tail -n 1"
run_once: true
register: HTTPD_SITE_VERSION
delegate_to: 127.0.0.1
-
name: "Get GIT version from site"
shell: "curl -s
'https://api.github.com/repos/git/git/tags?per_page=100' | jq -r '.[] |
.name' | sort -V | grep ^v2 | tail -n 1 | cut -f1 -d'-' | tail -
run_once: true
register: GIT_SITE_VERSION
delegate_to: 127.0.0.1
-
name: "Get current version PHP"
register: CURRENT_PHP_VERSION
shell: "/usr/local/php/bin/php --version | head -c 10 | tail -c 6"
-
name: "Get current version PHP"
register: CURRENT_HTTPD_VERSION
shell: "httpd -v | grep 2.4 | tail -n 1 | tail -c 14 | head -c 6"
-
name: "Get current version PHP"
register: CURRENT_GIT_VERSION
shell: "git --version | tail -c 7"
- name: Write header
run_once: true
lineinfile: dest=/home/ncontu/test.txt create=yes line="LATEST
VERSION PHP {{PHP_SITE_RESPONSE.json.version}} HTTPD
{{HTTPD_SITE_VERSION.stdout_lines[0]VERSION.stdout_lines[0]}}"
delegate_to: 127.0.0.1
- name: Write to local disk
lineinfile: dest=/home/ncontu/test.txt insertafter=EOF create=yes
line="{{ ansible_fqdn }} {{CURRENT_PHP_VERSION.stdout_lines[0]}}
{{CURRENT_HTTPD_VERSI}} {{CURRENT_GIT_VERSION.stdout_lines[0]}}"
delegate_to: 127.0.0.1
when: CURRENT_PHP_VERSION.stdout_lines[0] !=
PHP_SITE_RESPONSE.json.version or CURRENT_HTTPD_VERSION.stdout_lines[0] !=
HTTPD_SITE_VERSION.stdout_lines[VERSION.stdout_lines[0] !=
GIT_SITE_VERSION.stdout_lines[0]
- name: Cat produced file
command: /bin/cat /home/ncontu/test.txt
register: details
delegate_to: 127.0.0.1
run_once: true
when: inventory_hostname == ansible_play_hosts_all[-1]
- name: Base64 produced file
command: base64 /home/ncontu/test.txt
register: basefile
delegate_to: 127.0.0.1
run_once: true
when: inventory_hostname == ansible_play_hosts_all[-1]
Any help would be much appreciated.
Thanks
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5b4d3382-6545-4213-a915-ea8f6e3d85b5%40googlegroups.com.