Hi,
I am new in ansible world, trying to figure out playbook where I use 'grep' to check for netmask address from a text file and capture the exit code with 'register' ( see below).
My vars/main.yml looks like this:
ipmitool_lan:
root:
netmask: 255.0.0.0
defgw: 10.1.1.1
My tasks/main.yml looks like this:
---
####
- name: HP server netmask setup check
command: grep -q {{ item.value.netmask }} /tmp/hponcfg.out
register: ipmask
with_dict: "{{ ipmitool_lan }}"
ignore_errors: yes
#- debug: msg= "{{ ipmask.rc }}"
- block:
- name: HP server setup netmask
replace:
path: "/tmp/hponcfg.out"
regexp: >-
(<SUBNET_MASK.VALUE.)(=)(.*\b)("\/>)
replace: >-
\1 \2 "{{ item.value.netmask }}\4
with_dict: "{{ ipmitool_lan }}"
when:
- ansible_system_vendor == 'HP'
- ipmask.rc != 0
My /tmp/hponcfg.out file looks like this:
--------snip-------
<SPEED_AUTOSELECT VALUE = "Y"/>
<NIC_SPEED VALUE = "10"/>
<FULL_DUPLEX VALUE = "N"/>
<IP_ADDRESS VALUE = "10.3.254.221"/>
<SUBNET_MASK VALUE = "255.255.0.0"/>
<GATEWAY_IP_ADDRESS VALUE = "10.1.1.1"/>
-------snip-----------
when the above playbook is run, I get the following error:
TASK [ipmi : HP server setup netmask] ****************************************************************************
task path: /data/ansible-hpc/production/global/pkgs/20180703_2227/roles/ipmi/tasks/main.yml:14
fatal: [compute-13-11]: FAILED! => {
"msg": "The conditional check 'ipmask.rc != 0' failed. The error was: error while evaluating conditional (ipmask.rc != 0): 'dict object' has no attribute 'rc'\n\nThe error appears to have been in '/data/ansible-hpc/production/global/pkgs/20180703_2227/roles/ipmi/tasks/main.yml': line 14, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n- block:\n - name: HP server setup netmask\n ^ here\n"
data structure of this run looks like this, where is clear that 'ipmask.rc != 0'
"item": {
"key": "root",
"value": {
"defgw": "10.1.1.1",
"netmask": "255.0.0.0"
}
},
"msg": "non-zero return code",
"rc": 1,
"start": "2018-07-06 23:44:31.061066",
"stderr": "",
"stderr_lines": [],
"stdout": "",
"stdout_lines": []
It looks like "rc": value is '1' , doesn't it? Well, I am no expert at this but at least that's what I can see.
Not sure what I am doing wrong, I am out of ideas. I need to get this resolved to move forward, so, any help will be greatly appreciated!