Hii
If you
1. Properly format your playbook to be a list of plays
2. Use shell
3. Don't use {{ }} around the var in your debug task
Then it works:
TASK [get file server's IP address]
****************************************************************
changed: [villa -> localhost]
TASK [debug]
***************************************************************************************
ok: [villa] =>
fs_ip_addr:
changed: true
cmd: grep prod-fs1 /etc/hosts | awk '{ print $0 }'
delta: '0:00:00.008973'
end: '2020-03-04 00:36:05.873228'
failed: false
rc: 0
start: '2020-03-04 00:36:05.864255'
stderr: ''
stderr_lines: []
stdout: 10.10.10.20 prod-fs1
stdout_lines:
- 10.10.10.20 prod-fs1
But I would also recommend:
4. Dropping privilege escalation for local actions
5. Use "print $1" as this will match the actual IP
6. Use 'stdout' sa this will be the actual IP
Thus the playbook would be:
---
- hosts: all
gather_facts: yes
become: yes
pre_tasks:
- name: get file server's IP address
shell: "grep prod-fs1 /etc/hosts | awk '{ print $1 }'"
register: fs_ip_addr
become: no
delegate_to: localhost
- debug: var=fs_ip_addr.stdout
And then output would be:
TASK [debug]
***********************************************************************************************
ok: [villa] =>
fs_ip_addr.stdout: 10.10.10.20
Although shell+grep+awk still sounds fragile
Dick
On Tue, 3 Mar 2020 at 22:47, Robert F <[email protected]> wrote:
> I neglected to mention that I did try the shell and it did not fix the
> problem. But thanks for the suggestion!
>
> On Tuesday, March 3, 2020 at 1:32:24 PM UTC-8, Juerg Ritter wrote:
>>
>> Hi Robert,
>>
>> Try using the shell module instead of the command module. The command
>> module doesn't execute a command in a shell, hence you cannot use shell
>> functionality such as a pipes and redirections.
>>
>> Hope that helps!
>>
>> --Juerg
>>
>> --
> 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/19190c01-4a38-4e11-8d16-eca599df6037%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/19190c01-4a38-4e11-8d16-eca599df6037%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
--
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/CAL8fbwMpNxrujF-Hw5O8_7iXmTi9Qxq_LmzUx3w_vNKVv1YWDQ%40mail.gmail.com.