---
- hosts: all
roles:
- role: aos-wlan-ansible-role
tasks:
- name: 获取当前时间
vars:
ansible_connection: local
debug:
msg: "{{ansible_date_time.iso8601_basic_short}}"
register: current_time
- name: 备份配置{{current_time.msg}}.tar.gz 到 flash
aos_show_command:
command: "backup config configbackup_{{current_time.msg}}"
register: result_bak
- name: 上传备份配置{{current_time.msg}}.tar.gz 到 scp 服务器 172.16.0.109/aos_lab1/
aos_show_command:
command: "copy flash: configbackup_{{current_time.msg}}.tar.gz scp: 172.16.0.109 root /root/pythonlab/ansible/configbackup_{{current_time.msg}}.tar.gz"
responses:
(.*)Password: "aruba123"
register: result_copy
failed:
TASK [上传备份配置20220121T164319.tar.gz 到 scp 服务器 172.16.0.109/aos_lab1/] *****************
task path: /Users/leo.ma/onlyleo/python/aruba_python/demo_playbook.yml:17
redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
fatal: [lab1-mm]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (aos_show_command) module: responses. Supported parameters include: command."}
Related
I am executing a PS script on a windows host and want to store its stdout in a file on an ansible local machine. I have a playbook like following:
---
- name: Check Antivirus software
hosts: all
become: false
gather_facts: no
tasks:
- name: Get AV details
win_shell: |
echo "script printing data on stdout"
register: result
- name: save response
copy:
content: '{{ result.stdout }}'
dest: '{{ response_file }}'
delegate_to: localhost
From the above playbook, 1st task gets executed without any issues. But 2nd task gives the following error.
TASK [save response] *******************************************************************************************************************************************
fatal: [20.15.102.192 -> localhost]: UNREACHABLE! => {"changed": false, "msg": "ntlm: HTTPSConnectionPool(host='localhost', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f4940760208>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true}
I also tried local_action which is also giving the same error.
I am using juniper module for Ansible, however I'm having the issue below. Do you have any idea ?
fatal: [172.31.30.158]: FAILED! => {"changed": false, "msg": "Failure checking the configuraton: RpcTimeoutError(host: 172.31.30.158, cmd: commit-configuration, timeout: 10)"}
Playbook:
- name: "Configure Device"
hosts: junos
connection: local
timeout: 50
gather_facts: no
tasks:
- name: "Configure op script"
juniper.device.config:
config_mode: "private"
check_commit_wait: 20
load: "set"
src: "test.txt"
register: response
- name: "Print the config changes"
debug:
var: response
---
- name: Adding the host server
hosts: localhost
vars_prompt:
- name: "Server"
prompt: "Server IP"
private: no
- name: "User"
prompt: "Username"
default: "Ubuntu"
private: no
- name: "Passwd"
prompt: "Password"
private: yes
encrypt: "sha512_crypt"
- name: "IdFile"
prompt: "Identity file path(~/.ssh/id_rsa.pub)"
private: no
when: Passwd is undefined
- name: "cmd"
prompt: "Which command you want to run 1.ls -l 2.Top 3.uptime."
private: |-
no
tasks:
- name: Add host server
add_host:
name: "{{ Server }}"
ansible_ssh_user: "{{ User }}"
ansible_ssh_private_key_file: "{{ IdFile }}"
when: IdFile is defined
- name: Add host server
add_host:
name: "{{ Server }}"
ansible_ssh_user: "{{ User }}"
ansible_ssh_pass: "{{ Passwd }}"
when: Passwd is defined
- name: check OS name
shell: uname -a
delegate_to: "{{ Server }}"
- hosts: "{{ Server }}"
#below are for testing only.
tasks:
- name: Execute a command using the shell module
become: true
#become_user: root
shell: uname -a
- name: check OS name
shell: uname -a
delegate_to: "{{ Server }}"
This is giving below error:
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Authentication failure.", "unreachable": true}
Can anybody check the above code once and suggest the changes?
Set up module in ansible gives an error when i tried to set custom facts on host machine using control machine
---
- hosts: test-servers
gather_facts: false
tasks:
- name: deleting Facts directory
file:
path: /etc/ansible/facts.d/
state: absent
- name: Creates a directiory
file:
path: /etc/ansible/facts.d/
recurse: yes
state: directory
- name: Copy custom date facts to host machine
copy:
src: /app/ansible_poc/roles/custom_facts/templates/facts.d/getdate.fact
dest: /etc/ansible/facts.d/getdate.fact
mode: 0755
- name: Copy custom role facts to host machine
copy:
src: /app/ansible_poc/roles/custom_facts/templates/facts.d/getrole.fact
dest: /etc/ansible/facts.d/getrole.fact
mode: 0755
- name: Reloading facts
setup:
- name: Display message
debug:
msg: "{{ ansible_local.getdate.date.date }}"
- name: Display message
debug:
msg: "{{ ansible_local.getrole.role.role }}"
I get following error when i tried to collect facts of ansible host machine. I have set up a file getdate.fact and getrole.fact which has code respectively
#############getdate.fact###############
echo [date]
echo date= `date`
########################################
#############getrole.fact###############
echo [role]
echo role= `whoami`
########################################
and when i tried to run the playbook main.yml then it following error.
[root#ansibletower tasks]# ansible -m setup test-servers
192.168.111.28 | FAILED! => {
"changed": false,
"cmd": "/etc/ansible/facts.d/getdate.fact",
"msg": "[Errno 8] Exec format error",
"rc": 8
}
192.168.111.27 | FAILED! => {
"changed": false,
"cmd": "/etc/ansible/facts.d/getdate.fact",
"msg": "[Errno 8] Exec format error",
"rc": 8
}
If I recall correctly, executables are expected to return JSON:
#!/bin/bash
echo '{ "date" : "'$( date )'" }'
You probably need to add "shebang" line to your fact scripts. I.e., getdate.fact should look like:
#!/bin/sh
echo [date]
echo date=`date`
I want to print storage filer version output generated by the na_ontap_command module using ansible-playbooks.
I tried to register the result in a variable and print it using a debug message, but I am getting error.
`---
- hosts: localhost
name: run ontap cli command
gather_facts: no
connection: local
vars_files:
- var_file.yml
tasks:
- name: run ontap cli command
na_ontap_command:
command: ['version']
https: true
validate_certs: false
hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"
register: command_result
- debug:
var: command_result.stdout_lines
`
My playbook should return the version of the storage filer NetApp Release 9.1P8
This is the debug I am getting:
>TASK [debug] ***********************************************************************************************************************************************************************************************************
ok: [localhost] => {
"command_result.stdout_lines": "VARIABLE IS NOT DEFINED!"
}
---
- hosts: localhost
name: run ontap cli command
gather_facts: no
connection: local
vars_files:
- var_file.yml
tasks:
- name: run ontap cli command
na_ontap_command:
command: ['version']
https: true
validate_certs: false
hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"
register: command_result
- debug:
var: command_result
Result after executing:
TASK [debug] ***********************************************************************************************************************************************************************************************************
ok: [localhost] => {
"command_result": {
"changed": true,
"failed": false,
"msg": "<results xmlns=\"http://www.netapp.com/filer/user\" status=\"passed\"><cli-output>NetApp Release 9.1P8: Wed Aug 30 13:33:41 UTC 2017\n\n</cli-output><cli-result-value>1</cli-result-value></results>"
}
}
Try this:
register: output
- name: print CLI Output
debug:
msg:
- "output": "{{output.msg.split('\n')}}