Trying to gather facts to write to local file on ansible server

406 views
Skip to first unread message

Chris Bidwell - NOAA Federal

unread,
Sep 29, 2021, 4:13:14 PM9/29/21
to ansible...@googlegroups.com
Hi all!

So this has worked at one point but is no longer.  

I'm trying to gather information on each of my rhel clients and write that information to one file on my answer server.  

Here is my playbook:

---    
- hosts: 'ALL_LINUX'
  become: yes
  become_method: sudo
  vars_files:
    - passwd.yml
    - vars.yml
       
  vars:
    - RHEL_INV: "/home/chris.bidwell/rhel_inventory"
    - VAR: "{{ hostvars[item].facter_virtual }}"
       
  tasks:
    - name: Workstation or Server?
      shell: cat /etc/redhat-release | awk '{print $5}'
      register: rh_type
      tags: name
       
    - name: Append to file
      lineinfile:
        dest: "{{ RHEL_INV }}"
        line: "{{ ansible_default_ipv4.address }},{{ inventory_hostname }},{{ ansible_default_ipv4.macaddress }},{{ansible_distribution }}, {{ ansible_distribution_major_version }}, {{ rh_type.stdout }}"
        insertafter: EOF
        create: yes
      delegate_to: localhost
       
    - debug:
        msg: "{{ ansible_default_ipv4.address }},{{ inventory_hostname }},{{ ansible_default_ipv4.macaddress }},{{ ansible_distribution }} {{ ansible_distribution_major_version }} {{ rh_type.stdout }}"
      with_items: "{{ ansible_play_hosts }}"


Where my output is saying:
chris.bidwell@atsb-swpc-pup-svr-lx:roles$ ap rhel_inventory.yml -K --limit 'rhel8-base-lx'
BECOME password:

PLAY [ALL_LINUX] **********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************************************************************************
ok: [rhel8-base-lx]

TASK [Make sure files exist] **********************************************************************************************************************************************************************************************
Sorry, try again.
failed: [rhel8-base-lx] (item=/home/chris.bidwell/rhel.svr) => {"ansible_loop_var": "item", "changed": false, "item": "/home/chris.bidwell/rhel.svr", "module_stderr": "[sudo via ansible, key=hkjseytyeuvgdyqbndymptpnvkghxbld] password:\nsudo: no password was provided\nsudo: 1 incorrect password attempt\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
Sorry, try again.
failed: [rhel8-base-lx] (item=/home/chris.bidwell/rhel.wkstn) => {"ansible_loop_var": "item", "changed": false, "item": "/home/chris.bidwell/rhel.wkstn", "module_stderr": "[sudo via ansible, key=vhtrrvzwdhssvgmxrexsvvhxvzyonmeu] password:\nsudo: no password was provided\nsudo: 1 incorrect password attempt\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}


PLAY RECAP ****************************************************************************************************************************************************************************************************************
rhel8-base-lx              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Matt Martz

unread,
Sep 29, 2021, 4:15:32 PM9/29/21
to ansible...@googlegroups.com
Your output doesn't match the provided play, however, I'm guessing you need a `become: no` on the task that has `delegate_to: localhost` on it.

--
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/CAHKi8CgdMkrnAeCarf5S1eJiigr%2B9orVj8RYRq2ttRxF%3DPrOnA%40mail.gmail.com.


--
Matt Martz
@sivel
sivel.net

Chris Bidwell - NOAA Federal

unread,
Sep 29, 2021, 4:41:17 PM9/29/21
to ansible...@googlegroups.com
Dang!  Thank you!



--

Chris Bidwell, CISSP
Space Weather Prediction Center
National Oceanic Atmospheric Administration
email: chris.b...@noaa.gov
office: 303-497-3204
mobile: 720-496-3126

Mike Eggleston

unread,
Sep 29, 2021, 4:52:06 PM9/29/21
to ansible...@googlegroups.com
I’m over at FTC. Give me your email at NOAA and I’ll forward you the playbook I use.

Brian Coca

unread,
Oct 7, 2021, 12:29:35 PM10/7/21
to Ansible Project
Don't really need a play, just:

ansible -m gather_facts --tree /dir/with/json/file/per/host/ all


--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages