--
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/b708d4e2-ded7-44f0-b68a-866e93ec860bn%40googlegroups.com.
Assuming “hostname” means a fully qualified domain name, then the following may help you.
---
- hosts: all
gather_facts: True
become: false
tasks:
- name: show file contents
debug:
msg: "{{ lookup('file', 'customer-expects.txt') }}"
- name: Correct kernel?
set_fact:
# These dashes matter.
expectation: |-
{%- if lookup('file', 'customer-expects.txt')
is regex([ansible_system,ansible_fqdn,ansible_kernel]|join(' ')|regex_escape()) -%}
matched
{%- else -%}
missed
{%- endif -%}
- name: Report via Debug
run_once: True
debug:
msg: |
{% for exp in ['missed', 'matched', 'error'] %}
Kernel_expectations_{{ exp }}:
{% for hosti in ansible_play_hosts_all|sort %}
{% if hostvars[hosti]['expectation']|d('error') == exp %}
- {{ hosti }}
{% endif %}
{% endfor %}
{% endfor %}
This produces the following output given the command
ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook customer-expects.yml --limit flakey.sample.net,shaggy.sample.net,scooby.sample.net,clyde.sample.net -v
Using /home/utoddl/.ansible.cfg as config file
PLAY [all] ******************************
TASK [Gathering Facts] ****************
fatal: [flakey.sample.net]: UNREACHABLE! => changed=false
msg: 'Failed to connect to the host via ssh: uto...@flakey.sample.net: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).'
unreachable: true
ok: [scooby.sample.net]
ok: [shaggy.sample.net]
ok: [clyde.sample.net]
TASK [show file contents] **************
ok: [clyde.sample.net] =>
msg: |-
Linux flakey.sample.net 5.15.11-200.fc35.x86_64
Linux clyde.sample.net 5.15.11-200.fc35.x86_64
Linux shaggy.sample.net 5.15.11-200.fc35.x86_64
Linux scooby.sample.net 5.15.11-200.fc35.x86_64
Linux loaner.sample.net 5.15.11-200.fc35.x86_64
TASK [Correct kernel?] *****************
ok: [clyde.sample.net] => changed=false
ansible_facts:
expectation: matched
ok: [shaggy.sample.net] => changed=false
ansible_facts:
expectation: missed
ok: [scooby.sample.net] => changed=false
ansible_facts:
expectation: matched
TASK [Report via Debug] **************
ok: [clyde.sample.net] =>
msg: |-
Kernel_expectations_missed:
- shaggy.sample.net
Kernel_expectations_matched:
- clyde.sample.net
- scooby.sample.net
Kernel_expectations_error:
- flakey.sample.net
PLAY RECAP ***************************
clyde.sample.net : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
shaggy.sample.net : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
flakey.sample.net : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
scooby.sample.net : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3f4e20ff-2ece-4441-ae03-d70a5802ca2cn%40googlegroups.com.
-- Todd
Right. I did say
“Assuming “hostname”means a fully qualified domain name”, which is
not the case. Change ansible_fqdn
to ansible_hostname
in the “Correct kernel?” task and see if that helps.
Also, if you prefix
your ansible-playbook
command with ANSIBLE_STDOUT_CALLBACK=yaml
(or export the environment variable) you may have more joy looking
at your output.
Hi Todd,
--
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/9a2c23e7-f3de-9a01-442e-e6728dab522b%40gmail.com.
The goalpost keeps moving! Is this (the six lines of data below) from one column of an Excel sheet? From what you described before, I expected
Linux hostname00 4.18.0-193.el8.x86_64
Linux hostname01 4.13.2-120.el8.x86_64
Linux hostname03 4.18.0-193.el8.x86_64
Linux hostname04 4.13.2-120.el8.x86_64
[...etc...]
But now I’m seeing two identical lines following that pattern, mixed with other lines we’ve not heard about before, and nothing to map the “^Linux” lines to actual hosts' names.
Or is the “Expected value” one column heading, while “Installed Packeages” [sic] is a second column heading and it just got stuck under the first b/c it was exported from Excel as a .txt file? But which host(s) are the Installed Packages matched up with, and how? Or maybe there’s a separate sheet per host in the Excel workbook? It looks like it didn’t survive exporting from Excel particularly well.
And, now that I’m seeing the “Installed Packeages” bit, I’m expecting that to turn into one or more Ansible “package” module steps, in which case there’s some other non-trivial work ahead to transform this requirements-as-spreadsheet into actionable Ansible yaml inputs, in which case the prior exercise is probably moot.
I really want this to
work for you. Perhaps it would be helpful to provide the input
data spreadsheet as provided by the customer before it’s
undergone exporting or other transformations. Although I
understand if you need to obfuscate hostnames. If you do, don’t
change them all to the same string. Are the two instances of
“hostname” below really literally “hostname” (and therefore
identical), or do they stand in for originally distinct hosts’
names? And how do those hosts map to sets of installed packages?
On 1/4/22 11:24 AM, Marian Saldhana wrote:
For eg:
Expected value
Red Hat EnterpriseLinux release 8.2 (Ootpa)
Linux hostname 4.18.0-193.el8.x86_64
Linux hostname 4.18.0-193.el8.x86_64
Installed Packeages
FJSVsnap.noarch 7.00-1 @System