---
hosts: all
gather_facts: yes
become: yes
pre_tasks:
- name: get file server's IP address
command: "grep prod-fs1 /etc/hosts | awk '{ print $0 }'"
register: fs_ip_addr
delegate_to: localhost
- debug: var={{ fs_ip_addr }}TASK [get file server's IP address] *************************************************************************************************************************************************
fatal: [prod-web1.example.com -> localhost]: FAILED! => {"changed": true, "cmd": ["grep", "prod-fs1", "/etc/hosts", "|", "awk", "{ print $0 }"], "delta": "0:00:00.010303", "end": "2020-03-03 12:24:36.207656", "msg": "non-zero return code", "rc": 2, "start": "2020-03-03 12:24:36.197353", "stderr": "grep: |: No such file or directory\ngrep: awk: No such file or directory\ngrep: { print $0 }: No such file or directory", "stderr_lines": ["grep: |: No such file or directory", "grep: awk: No such file or directory", "grep: { print $0 }: No such file or directory"], "stdout": "/etc/hosts:45.79.93.135 prod-fs1.example.com prod-fs1", "stdout_lines": ["/etc/hosts:45.79.93.135 prod-fs1.example.com prod-fs1"]}
PLAY RECAP **************************************************************************************************************************************************************************
prod-web1.example.com : ok=7 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0;p - name: get file server's IP address
set_fact: fs_ip_addr=hostvars[groups['fileservers'][0]]['ansible_eth0']['ipv4']['address']deploy-webservers.yml -I inventory -l webserversHi,
Not read everything but first thing is that if you have a pipe in
a command call.... you should use shell module instead... That
should fix your first issue.
Regards,
JYL
--
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/21a85286-91fb-404c-a9d5-f30608be1c3d%40googlegroups.com.
--
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/21a85286-91fb-404c-a9d5-f30608be1c3d%40googlegroups.com.
Jürg Ritter, RHCE
ConsultantEuropaallee 41
CH-8021 Zürich
--
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/19190c01-4a38-4e11-8d16-eca599df6037%40googlegroups.com.