I have ansible code that works quite well - logs on to the server I want and so forth.
The way it is designed, system asks for your username and password, then logs into the host.
Using ansible code, I would like to gather information after I login and then output the results.
The information that I would like to gather:
hostname
ip address
So I would like output that says:
<>–> <>
I would only like this information to be outputted to screen. Nothing else.
Is it messy because $ip has extra content, or because the output of an Ansible job is an Ansible job log? I’m not sure what benefit you get by involving Ansible in the process. It seems like it would be simpler to say
If the point is to make the output of Ansible look like something other than an Ansible job log, then I think a re-evaluation of the technique is in order.
It is unclear to me why you are using shell at all? Isn’t this information available as an Ansible Fact, so you should be able to use those to echo (debug-msg) however you want?
As @jrglynn2 suggested, take advantage of the facts that Ansible gathers by default.
The following will display the short hostname, fully qualified domain name, as well as the default ipv4 and ipv6 addresses. It’s possible for IPv4/IPv6 to be undefined, so this snippet sets a default message instead of failing the debug task whenever that’s the case.
Based on what it seems you want in your original post, msg: "{{ ansible_fqdn | default(ansible_hostname) }} --> {{ ansible_default_ipv4.address }}" is probably what you’re looking for.