unable to send register value on remote server.


  • 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

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.

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

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.

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

Sort out, it’s working now, Thanks Brian for your help.

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]#

deepak from BEA Systems??

Nope