我要检查URL状态是否为200。
我有用户列表,使用URI模块,我可以循环获取返回状态代码为200或403(预期)。但是,如何检查代码是否为200。
输入 abc 定义 吉
- name: Check if user is added in to DLs
uri:
url: http://example.net:8080/user_in_dl?user={{item}}
return_content: yes
status_code: 200
register: this
failed_when: "'true' not in this.content"
with_items: "{{ usernames.strip().replace(' ', '').replace(',', '\n').split('\n') }}"
delegate_to: 127.0.0.1
ignore_errors: yes
run_once: true
- name: Reading User file to check if user is not already added to access list
shell: "cat /root/usersfile"
register: ulist
delegate_to: 127.0.0.1
run_once: true
- name: Checking if unix ID is available.
shell: |
cat /etc/remote_files/master | awk -F ":" '{ print $1 } ' | grep -w {{ item }}
register: uid
delegate_to: 127.0.0.1
with_items: "{{ usernames.strip().replace(' ', '').replace(',', '\n').split('\n') }}"
ignore_errors: yes
run_once: true
- name: Reading the auto.homes file to check if user have home directory
shell: 'cat /root/auto.homes | grep -iw "\b{{ item }}\b" | cut -d " " -f1'
with_items: "{{ usernames.strip().replace(' ', '').replace(',', '\n').split('\n') }}"
register: uhomelist
delegate_to: 127.0.0.1
run_once: true
- debug:
msg: "Condtion was successful"
when: item not in ulist.stdout and item != "" and (this.results | map(attribute='status') | list) == 200 and (uid.results | map(attribute='stdout') | list) != ""
with_items: "{{ this.results | map(attribute='status') | list }}"
注意-with_items的值为=用户名或“” 任何帮助。