ansible yml error

338 views
Skip to first unread message

stac...@gmail.com

unread,
Nov 18, 2016, 7:52:05 AM11/18/16
to Ansible Project
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
---
- hosts: patch
  tasks:
   - name: I am rebooting servers!! You go and have some coffe!
     shell: sh -c '/usr/bin/reboot'
     async: 0
     poll: 0
     ignore_errors: true

   - name: I am waiting for server to come back!
     local_action: wait_for host={{ inventory_hostname }} port=22 state=started delay=150 timeout=500
     become: no

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

   - name: Updating patches
     shell: sh -c "sudo yum update -y"


stac...@gmail.com

unread,
Nov 18, 2016, 8:25:43 AM11/18/16
to Ansible Project

Ansible version is  ansible-2.1.1.0-1 

Kai Stian Olstad

unread,
Nov 18, 2016, 9:41:52 AM11/18/16
to ansible...@googlegroups.com
On 18. nov. 2016 12:49, stac...@gmail.com wrote:
> - name: Subscribing a new channel
> shell: sh -c "rhnreg_ks --activationkey 1-vblock20161026"
> shell: sh -c "rhnreg_ks --activationkey 1-vblock20161026 --force"

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.

--
Kai Stian Olstad

stac...@gmail.com

unread,
Nov 18, 2016, 10:16:08 AM11/18/16
to Ansible Project, ansible-pr...@olstad.com
Added like below , still am getting error  :( 



  - 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: ''

Kai Stian Olstad

unread,
Nov 18, 2016, 10:25:25 AM11/18/16
to ansible...@googlegroups.com
On 18. nov. 2016 16:16, stac...@gmail.com wrote:
> Added like below , still am getting error :(

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"

--
Kai Stian Olstad

stac...@gmail.com

unread,
Nov 18, 2016, 2:17:42 PM11/18/16
to Ansible Project, ansible-pr...@olstad.com
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

Kai Stian Olstad

unread,
Nov 19, 2016, 2:31:16 PM11/19/16
to ansible...@googlegroups.com
On 18. nov. 2016 20:17, stac...@gmail.com wrote:
> - 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

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages