ansible yml error

Any idea about the below error -

[sysadm@pclprdftsnsoft1 ~]$ ansible-playbook 2.yml
[WARNING]: While constructing a mapping from /home/sysadm/2.yml, line 14, column 6, found a duplicate dict key
(shell). Using last defined value only.

PLAY [patch] *******************************************************************

TASK [setup] *******************************************************************
ok: [ccltstftsmrk1]

TASK [I am rebooting servers!! You go and have some coffe!] ********************
fatal: [ccltstftsmrk1]: FAILED! => {“changed”: true, “cmd”: “sh -c ‘/usr/bin/reboot’”, “delta”: “0:00:00.015728”, “end”: “2016-11-18 06:33:54.544235”, “failed”: true, “rc”: 1, “start”: “2016-11-18 06:33:54.528507”, “stderr”: “reboot: Need to be root”, “stdout”: “”, “stdout_lines”: , “warnings”: }
…ignoring

TASK [I am waiting for server to come back!] ***********************************
ok: [ccltstftsmrk1 → localhost]

TASK [Subscribing a new channel] ***********************************************
fatal: [ccltstftsmrk1]: FAILED! => {“changed”: true, “cmd”: “sh -c "rhnreg_ks --activationkey 1-vblock20161026 --force"”, “delta”: “0:00:00.006615”, “end”: “2016-11-18 06:36:31.115522”, “failed”: true, “rc”: 127, “start”: “2016-11-18 06:36:31.108907”, “stderr”: “sh: rhnreg_ks: command not found”, “stdout”: “”, “stdout_lines”: , “warnings”: }

NO MORE HOSTS LEFT *************************************************************
[WARNING]: Could not create retry file ‘2.retry’. [Errno 2] No such file or directory: ‘’

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

[sysadm@pclprdftsnsoft1 ~]$

code -

[sysadm@pclprdftsnsoft1 ~]$ cat 2.yml

Ansible version is ansible-2.1.1.0-1

One task can only have one module.
You can add a "- name" to the last shell module or add a - in front of the shell module.

Added like below , still am getting error :frowning:

  • name: Subscribing a new channel
    shell: sh -c “rhnreg_ks --activationkey 1-vblock20161026”

  • name: Subscribing a new channel forcefully
    shell: sh -c “rhnreg_ks --activationkey 1-vblock20161026 --force”

TASK [I am waiting for server to come back!] ***********************************
ok: [ccltstftsmrk1 → localhost]

TASK [Subscribing a new channel] ***********************************************
fatal: [ccltstftsmrk1]: FAILED! => {“changed”: true, “cmd”: “sh -c "rhnreg_ks --activationkey 1-vblock20161026"”, “delta”: “0:00:00.272494”, “end”: “2016-11-18 10:13:52.624698”, “failed”: true, “rc”: 1, “start”: “2016-11-18 10:13:52.352204”, “stderr”: “”, “stdout”: “You must be root to run /usr/sbin/rhnreg_ks”, “stdout_lines”: [“You must be root to run /usr/sbin/rhnreg_ks”], “warnings”: }

NO MORE HOSTS LEFT *************************************************************
[WARNING]: Could not create retry file ‘patch.retry’. [Errno 2] No such file or directory: ‘’

Added like below , still am getting error :frowning:

Have you read the error message?

  - name: Subscribing a new channel
     shell: sh -c "rhnreg_ks --activationkey 1-vblock20161026"

   - name: Subscribing a new channel forcefully
     shell: sh -c "rhnreg_ks --activationkey 1-vblock20161026 --force"

TASK [I am waiting for server to come back!]
***********************************
ok: [ccltstftsmrk1 -> localhost]

TASK [Subscribing a new channel]
***********************************************
fatal: [ccltstftsmrk1]: FAILED! => {"changed": true, "cmd": "sh -c
\"rhnreg_ks --activationkey 1-vblock20161026\"", "delta": "0:00:00.272494",
"end": "2016-11-18 10:13:52.624698", "failed": true, "rc": 1, "start":
"2016-11-18 10:13:52.352204", "stderr": "", "stdout": "You must be root to
run /usr/sbin/rhnreg_ks", "stdout_lines": ["You must be root to run
/usr/sbin/rhnreg_ks"], "warnings": }

The error message say "You must be root to run /usr/sbin/rhnreg_ks"

oops … I missed.

Now I have corrected like below … still bad luck with me … . Also If I executed these commands directly into clients servers and its working.

  • name: Subscribing a new channel
    shell: sh -c “sudo yum clean all”
  • shell: sh -c “sudo rhnreg_ks --activationkey 1-vblock20161026”
  • shell: sh -c “sudo rhnreg_ks --activationkey 1-vblock20161026 --force”

PLAY [patch] *******************************************************************

TASK [I am rebooting servers!! You go and have some coffe!] ********************
changed: [ccltstftsmrk1]
[WARNING]: Consider using ‘become’, ‘become_method’, and ‘become_user’ rather than running sudo

TASK [I am waiting for server to come back!] ***********************************
ok: [ccltstftsmrk1 → localhost]

TASK [Subscribing a new channel] ***********************************************
changed: [ccltstftsmrk1]

TASK [command] *****************************************************************
fatal: [ccltstftsmrk1]: FAILED! => {“changed”: true, “cmd”: “sh -c "sudo rhnreg_ks --activationkey 1-vblock20161026"”, “delta”: “0:00:00.270108”, “end”: “2016-11-18 14:06:44.477886”, “failed”: true, “rc”: 255, “start”: “2016-11-18 14:06:44.207778”, “stderr”: “”, “stdout”: “This system is already registered. Use --force to override”, “stdout_lines”: [“This system is already registered. Use --force to override”], “warnings”: }

NO MORE HOSTS LEFT *************************************************************
[WARNING]: Could not create retry file ‘patch.retry’. [Errno 2] No such file or directory: ‘’

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

   - name: Subscribing a new channel
     shell: sh -c "sudo yum clean all"
   - shell: sh -c "sudo rhnreg_ks --activationkey 1-vblock20161026"
   - shell: sh -c "sudo rhnreg_ks --activationkey 1-vblock20161026 --force"

[snip]

TASK [Subscribing a new channel]
***********************************************
changed: [ccltstftsmrk1]

TASK [command]
*****************************************************************
fatal: [ccltstftsmrk1]: FAILED! => {"changed": true, "cmd": "sh -c \"sudo
rhnreg_ks --activationkey 1-vblock20161026\"", "delta": "0:00:00.270108",
"end": "2016-11-18 14:06:44.477886", "failed": true, "rc": 255, "start":
"2016-11-18 14:06:44.207778", "stderr": "", "stdout": "This system is
already registered. Use --force to override", "stdout_lines": ["This system
is already registered. Use --force to override"], "warnings": }

It's failing on the first rhnreg_ks that doesn't have --force because it's already registered. It this circumstance rhnreg_ks return code is 255, everything higher than 0 is a failure for the shell module.
You can change this behavior with the failed_when.

Have you checked out these two module, maybe they can do what you are trying to do?

rhn_register - Manage Red Hat Network registration using the rhnreg_ks command
rhn_channel - Adds or removes Red Hat software channels