我正在使用一个剧本来卸载一个软件程序和剧本工作。本手册首先使用stat模块编写软件的二进制路径,然后使用when条件检查其是否存在,并在此基础上执行操作。
我还使用shell模块来运行using。下面是我的剧本
---
- name: Un-Install altris
hosts: all
gather_facts: False
strategy: free
serial: 100
tasks:
- name: Check if altris stop/start path exists
stat: path=/opt/altiris/notification/nsagent/bin/rcscript
register: altris_status
- name: stop the altris if path exits
shell: |
echo `hostname`
echo "-------------------------------"
/opt/altiris/notification/nsagent/bin/rcscript stop
when: altris_status.stat.exists == True
register: altris_stop
- name: Check if uninstall binary ptah exists
stat: path=/opt/altiris/notification/nsagent/bin/aex-uninstall
register: altris_uninstall
- name: un-installing altris
shell: |
echo `hostname`
echo "-------------------------------"
yes | /opt/altiris/notification/nsagent/bin/aex-uninstall
when: altris_uninstall.stat.exists == True
register: altris_trim
############# Storing the logs locally for the STDOUT ############
- name: Storing the remote Hosts Output locally for altris
#lineinfile: create=yes dest=/Karn/altris_uninstall.logs line="{{ altris_trim.stdout }}"
lineinfile: create=yes dest=/Karn/test_uninstall.logs line="{{ altris_trim.stdout }}"
delegate_to: 127.0.0.1
- name: Storing the remote Hosts Output locally for altris
#lineinfile: create=yes dest=/Karn/altris1_stop.logs line="{{ altris_stop.stdout }}"
lineinfile: create=yes dest=/Karn/test_stop.logs line="{{ altris_stop.stdout }}"
delegate_to: 127.0.0.1注意:当我运行剧本时,它的工作正常,但是错误只出现在它找不到未安装的二进制路径的地方,并抛出下面的mesg错误:
[root@dev-ops Karn]# ansible-playbook altris_unistall2.yml
PLAY [Un-Install altris] ********************************************************************************************************************************************
Friday 15 December 2017 10:35:50 +0530 (0:00:00.112) 0:00:00.112 *******
TASK [Check if altris stop/start path exists] ***********************************************************************************************************************
ok: [dev-oracle]
Friday 15 December 2017 10:36:01 +0530 (0:00:10.179) 0:00:10.292 *******
TASK [stop the altris if path exits] ********************************************************************************************************************************
skipping: [dev-oracle]
Friday 15 December 2017 10:36:01 +0530 (0:00:00.019) 0:00:10.311 *******
TASK [Check if uninstall binary ptah exists] ************************************************************************************************************************
ok: [dev-oracle]
Friday 15 December 2017 10:36:11 +0530 (0:00:10.483) 0:00:20.795 *******
TASK [un-installing altris] *****************************************************************************************************************************************
skipping: [dev-oracle]
Friday 15 December 2017 10:36:11 +0530 (0:00:00.022) 0:00:20.817 *******
TASK [Storing the remote Hosts Output locally for altris] ***********************************************************************************************************
fatal: [dev-oracle]: FAILED! => {
"failed": true
}
MSG:
The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout'
The error appears to have been in '/Karn/altris_unistall2.yml': line 33, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
############# Storing the logs locally for the STDOUT ############
- name: Storing the remote Hosts Output locally for altris
^ here
exception type: <class 'ansible.errors.AnsibleUndefinedVariable'>
exception: 'dict object' has no attribute 'stdout'
to retry, use: --limit @/Karn/altris_unistall2.retry
PLAY RECAP **********************************************************************************************************************************************************
dev-oracle : ok=2 changed=0 unreachable=0 failed=1
Friday 15 December 2017 10:36:11 +0530 (0:00:00.037) 0:00:20.854 *******
===============================================================================
Check if uninstall binary ptah exists ----------------------------------------------------------------------------------------------------------------------- 10.48s
Check if altris stop/start path exists ---------------------------------------------------------------------------------------------------------------------- 10.18s
Storing the remote Hosts Output locally for altris ----------------------------------------------------------------------------------------------------------- 0.04s
un-installing altris ----------------------------------------------------------------------------------------------------------------------------------------- 0.02s
stop the altris if path exits -------------------------------------------------------------------------------------------------------------------------------- 0.02s如果我需要在我的剧本里有任何内容的话..。有点像ingore_error..。
发布于 2017-12-15 05:18:36
跳过un-installing altris任务,因此altris_trim不包含stdout键。
您要么需要将when: stdout in altris_trim添加到Storing the remote Hosts Output locally for altris,要么使用与un-installing altris相同的条件。
同样的情况也适用于下一个任务和altris_stop.stdout。
https://stackoverflow.com/questions/47826161
复制相似问题