unable to send register value on remote server.

50 views
Skip to first unread message

Deepak Sharma

unread,
Aug 25, 2018, 5:09:02 PM8/25/18
to Ansible Project
---
- hosts: all
  gather_facts: true
  sudo: true
  tasks:

    - name: capture linux_os
      shell: "{{ item }}"
      register: prepatch
      with_items:
        - 'uname -a'
        - 'cat /etc/resolv.conf'
    - name: create directory
      file: path=/tmp/{{petch1}} state=directory

    - name: create backup
      copy: {{ prepatch.stdout }}  dest=/tmp/{{petch1}}-prepatch.txt
      ignore_errors: True

Unable to send to remote server

vinoth kumar

unread,
Aug 25, 2018, 11:45:25 PM8/25/18
to ansible...@googlegroups.com
On Sun, 26 Aug 2018 at 2:39 AM, Deepak Sharma <deepa...@gmail.com> wrote:
---
- hosts: all
  gather_facts: true
  sudo: true
  tasks:

    - name: capture linux_os
      shell: "{{ item }}"
      register: prepatch
      with_items:
        - 'uname -a'
        - 'cat /etc/resolv.conf'
    - name: create directory
      file: path=/tmp/{{petch1}} state=directory


What is the error screen.-also petch1 is nowhere mentioned .whatever given inside curly braces it taken as variable 

    - name: create backup
      copy: {{ prepatch.stdout }}  dest=/tmp/{{petch1}}-prepatch.txt
      ignore_errors: True

Unable to send to remote server

--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e625498f-386a-4329-9fb4-db21244b949b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Badraj Angirekula

unread,
Aug 27, 2018, 5:27:36 AM8/27/18
to ansible...@googlegroups.com
Hi all,
please help me.


Build ec2 instances with attaching multiple tags names :-
  For example- I have launched one ec2 instance with tag name "websever1" the next builds of ec2 instances should start with tag name webserver2 , webserver3 .... automatically.


Note: No two ec2 instances have same tag name.

Brian Coca

unread,
Aug 27, 2018, 11:42:06 AM8/27/18
to Ansible Project
Your copy syntax is invalid, i'm guessing this is what you want:

copy: content={{ prepatch.stdout }} dest=/tmp/{{petch1}}-prepatch.txt

It also looks wrong as prepatch is a list and does not have a stdout
but a .results, with each item having a stdout


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

Brian Coca

unread,
Aug 27, 2018, 11:46:19 AM8/27/18
to Ansible Project
sorry, missing 1/2 of previous, here would be the final 'copy':



- copy: content={{ prepatch.results|selectattr('stdout')|join('\n') }}
dest=/tmp/{{petch1}}-prepatch.txt

This will put into the destination file the output fo both commands
separated by a new line, which I think is your intention.

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

Deepak Sharma

unread,
Aug 27, 2018, 1:21:42 PM8/27/18
to ansible...@googlegroups.com
Hi  Brian ,

Still getting errors.

[root@station1 ansible]# ansible-playbook c2.yml
 [WARNING]: While constructing a mapping from /etc/ansible/c2.yml, line 5, column 7, found a duplicate dict key (register). Using last
defined value only.


PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [capture linux_os] ********************************************************
changed: [localhost] => (item=uname -a)
changed: [localhost] => (item=cat /etc/resolv.conf)

TASK [creating db_inventory_dir] ***********************************************
ok: [localhost]

TASK [copy] ********************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'petch1' is undefined\n\nThe error appears to have been in '/etc/ansible/c2.yml': line 17, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n        state: directory\n    - copy: content={{ prepatch.results|selectattr('stdout')|join('\\n') }}  dest=/tmp/{{petch1}}-prepatch.txt\n      ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes.  Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}
        to retry, use: --limit @/etc/ansible/c2.retry

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=1



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

--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7cBTJDKr5EUgNZownc8fAGyko6nk3__o7kmv2NysriNbQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Regards:
Deepak

REDUCE     -        REUSE      -       RECYCLE

P Save Earth. Think about the Environment before printing this e-mail!!

Deepak Sharma

unread,
Aug 27, 2018, 1:28:07 PM8/27/18
to Ansible Project
Sort out, it's working now, Thanks Brian for your help.

Deepak Sharma

unread,
Aug 27, 2018, 1:47:20 PM8/27/18
to ansible...@googlegroups.com
Guys i need to store value of commands at remote servers.which i run with shell module

but the value is not coming up.
it is coming line that

[root@station2 petch2]# cat prepatch.txt
[{"_ansible_parsed": true, "changed": true, "stdout": "Linux station2.example.com 3.10.0-327.el7.x86_64 #1 SMP Thu Oct 29 17:29:29 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux", "_ansible_item_result": true, "warnings": [], "delta": "0:00:00.007163", "stdout_lines": ["Linux station2.example.com 3.10.0-327.el7.x86_64 #1 SMP Thu Oct 29 17:29:29 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux"], "end": "2018-08-27 13:44:59.407023", "_ansible_no_log": false, "start": "2018-08-27 13:44:59.399860", "cmd": "uname -a", "item": "uname -a", "stderr": "", "rc": 0, "invocation": {"module_name": "command", "module_args": {"warn": true, "executable": null, "_uses_shell": true, "_raw_params": "uname -a", "removes": null, "creates": null, "chdir": null}}}, {"_ansible_parsed": true, "changed": true, "stdout": "# Generated by NetworkManager\nsearch localdomain example.com\nnameserver 192.168.1.2", "_ansible_item_result": true, "warnings": [], "delta": "0:00:00.008031", "stdout_lines": ["# Generated by NetworkManager", "search localdomain example.com", "nameserver 192.168.1.2"], "end": "2018-08-27 13:45:00.090280", "_ansible_no_log": false, "start": "2018-08-27 13:45:00.082249", "cmd": "cat /etc/resolv.conf", "item": "cat /etc/resolv.conf", "stderr": "", "rc": 0, "invocation": {"module_name": "command", "module_args": {"warn": true, "executable": null, "_uses_shell": true, "_raw_params": "cat /etc/resolv.conf", "removes": null, "creates": null, "chdir": null}}}][root@station2 petch2]#


--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Regards:
Deepak
PaaS Engineering and OperationOPTUM TECHNOLOGY
Mobile:  +91-9811576630 | Noida

Wendell MacKenzie

unread,
Aug 27, 2018, 1:48:08 PM8/27/18
to ansible...@googlegroups.com
deepak from BEA Systems??

To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.



--
Regards:
Deepak
PaaS Engineering and OperationOPTUM TECHNOLOGY
Mobile:  +91-9811576630 | Noida

REDUCE     -        REUSE      -       RECYCLE

P Save Earth. Think about the Environment before printing this e-mail!!

--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BFVkN5r9abTJ%3Depkof4f3u-a7qpgDAat9mTCpCDQkLaDhNFhQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--

D. Wendell MacKenzie
Software Developer

Email: mack...@gmail.com
Phone: 902-626-8708 (cell)
            

Deepak Sharma

unread,
Aug 27, 2018, 1:49:29 PM8/27/18
to ansible...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages