我在目标 Linux 上设置了自定义 SSH 密钥 host2。
我能够从Linux的密码sshhost1来host2使用下面的命令。
ssh -i /app/misc/myssh_keys/my_id_rsa myuser@host2
Run Code Online (Sandbox Code Playgroud)
然后我将其复制/app/misc/myssh_keys/my_id_rsa到我的 Windows 位置C:\putty\my_id_rsa
然后我尝试从 Windows 连接到 Linux host2,但它提示我输入密码而不是无密码登录。
下面是我的命令:
C:\putty\putty.exe -ssh -i C:\putty\my_id_rsa myuser@host2
Run Code Online (Sandbox Code Playgroud)
我得到以下带有密码提示的输出:
Unable to use key file "C:\putty\my_id_rsa" (OpenSSH SSH-2 private key)
Using username "myuser".
myhost@host2's password:
Run Code Online (Sandbox Code Playgroud)
以下是 Linux 的系统详细信息 host2
uname -a
Linux host2 3.10.0-1062.1.2.el7.x86_64 #1 SMP Mon Sep 16 14:19:51 EDT 2019 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
以下是 Windows 主机的系统详细信息
C:\Users>systeminfo
Host Name: mywinhost
OS Name: …Run Code Online (Sandbox Code Playgroud) test-juli.jar这是我的剧本,我尝试在目录下查找/app,但是,我希望/app/Patchbackup从搜索中排除文件夹。
以下是我的剧本:
tasks:
- name: Find test home directories under /app
find:
paths: /app
file_type: any
recurse: yes
depth: 4
patterns: 'test-juli.jar'
excludes: 'log,tmp,.installation,Patchbackup'
tags: always
register: tomjarfound
- debug:
msg: "ALL LISTED REFINED JARS: {{ item.path }}"
loop: "{{ tomjarfound.files }}"
Run Code Online (Sandbox Code Playgroud)
当我运行上面的代码时,我预计find不会在下面找到/app/Patchbackup,但输出显示它确实存在,尽管被排除在外。
这是输出:
TASK [debug] ***********************************************************************************************************************************************************
ok: [10.0.0.11] => (item=/app/apache-test-9.0.10/bin/test-juli.jar) => {
"msg": "ALL LISTED REFINED JARS: /app/apache-test-9.0.10/bin/test-juli.jar"
}
ok: [10.0.0.11] => (item=/app/Patchbackup/app/apache-test-9.0.10/bin/test-juli.jar) => {
"msg": "ALL LISTED REFINED JARS: …Run Code Online (Sandbox Code Playgroud) 我使用 Ansible 运行启动脚本,如下所示:
\n- name: Start service\n raw: "source ~/.profile; ~/start.sh"\nRun Code Online (Sandbox Code Playgroud)\n现在,我想继续检查上面启动的服务的 HTTP 状态,直到成功 \xe2\x80\x94 200。
下面是我如何检查 HTTP 状态200,但是,我不知道如何继续检查 2 分钟并报告 URL 是否仍然没有返回200。
- name: Detect if HTTp response is \'200\'\n uri:\n url: \'http://example.org/iportal/\'\n return_content: yes\n validate_certs: no\n status_code:\n - 200\n register: uri_output\nRun Code Online (Sandbox Code Playgroud)\n 我希望将C:\Users\myuser\Downloads\SFTP本地 Windows 文件夹中的所有文件上传到远程 SFTP 服务器myfolder目录。
我在 Windows 上运行 sftp 并实现上述目标时遇到多个问题。
以下是我的命令:
C:\putty\psftp.exe -b C:\putty\sftp_commands.txt -l myuser -pw mypass 10.8.44.86
Run Code Online (Sandbox Code Playgroud)
这是我的C:\putty\sftp_commands.txt文件:
mkdir myfolder
cd myfolder
lcd "C:\Users\myuser\Downloads\SFTP"
put "C:\Users\myuser\Downloads\SFTP\*.*"
Run Code Online (Sandbox Code Playgroud)
尽管该文件存在于我的本地 Windows 上,但我收到“无法打开”错误。
C:\Users\myuser\Downloads\SFTP\*.*当我更改为时,这有效C:\Users\myuser\Downloads\SFTP\file1.txt。
C:\Users\myuser\Desktop>C:\putty\psftp.exe -b C:\putty\sftp_commands.txt -l myuser -pw mypass 10.8.44.86
Using username "myuser".
Pre-authentication banner message from server:
| EFT Server Enterprise 7.3.2.8
End of banner message from server
Keyboard-interactive authentication prompts from server:
End of keyboard-interactive prompts from server
Remote …Run Code Online (Sandbox Code Playgroud) 我有以下剧本:
- name: Add hosts
include_tasks: "{{ playbook_dir }}/gethosts1.yml"
vars:
PROFILE_NUM: "{{ my_result }}"
loop: "{{ query('sequence', 'start=1 end='+(PROFILES)) }}"
loop_control:
loop_var: my_result
Run Code Online (Sandbox Code Playgroud)
我将剧本运行为:
ansible-playbook test.yml -e PROFILES=12
Run Code Online (Sandbox Code Playgroud)
这使我的 PROFILE_NUM 为 1,2,3,4,5...12
但是,我希望 PROFILE_NUM 为两位数,即 01,02,03,04,05....12
我尝试了以下方法,但出现错误PROFILE_NUM: "%02d{{ my_result }}"
你能建议一下吗?
我有一个非常基本的剧本,它只是使用shell module目标远程主机上的运行脚本。
然而,在输出中它没有说明python interpreter not found.
在每个目标上安装 python 不是我可以追求的解决方案。
是否可以使用我的 Ansible 自动化来运行剧本并使用 shell 模块执行脚本而无需依赖 python?
考虑到该剧将在本地或远程运行,我需要了解 ansible 的 remote_user 和 become_user 之间的区别。
之间的区别:
- hosts: all
become: yes
become_user: user1
- hosts: all
remote_user: user1
Run Code Online (Sandbox Code Playgroud)
如果在服务器之间设置了 ssh 密钥,会有什么区别吗?
我试图用谷歌搜索差异,但没有找到任何好的解释。
我的 jinja2 模板为变量生成正确的值
{{ vars[fruit | join("")] | default('ERR') }}
Run Code Online (Sandbox Code Playgroud)
变量 Fruit 的值为 83.6,它由 Ansible 的模板模块打印。
我想在jinja2模板中编写一个if条件,我想检查变量fruit的值是否大于70
{% if ( vars[fruit | join("")] | int ) > 70 %}
Run Code Online (Sandbox Code Playgroud)
超过70个
{% 万一 %}
然而,当我期望它成功时,“如果”条件却失败了。
我还尝试了以下方法:
{% if ( vars[fruit | join("")] | int > 70 ) %}
Run Code Online (Sandbox Code Playgroud)
我也尝试过
{% if vars[fruit | join("")] | int > 70 %}
Run Code Online (Sandbox Code Playgroud)
但是,它们都不起作用。您能告诉我需要做什么才能满足 if 条件吗?
我的 Jenkins 正在 https://myhost:9043 上运行,使用 Linux 上的独立战争,使用以下命令。
java -jar jenkins.war
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试以下 URL 时,https://myhost:9043/<any random text>显然找不到资源 uri。
然而,问题是我在浏览器中得到的输出为
HTTP 404 error URI not found Powered by Jetty://9.4.27.vXXXX
Run Code Online (Sandbox Code Playgroud)
我不想透露 Jetty 版本。
有没有办法为不正确的 URI 显示自定义错误页面,从而避免泄露 Jetty 版本?如果没有,我可以以某种方式隐藏 Jetty 版本,以免向匿名用户显示吗?
我不是一个纯粹的 Java 程序员,而只是一个 DevOps 管理员。
security jetty http-status-code-404 jenkins crlf-vulnerability
我的公司防火墙策略仅允许同一源和目标之间每分钟 60 秒 20 个连接。
因此,ansible 播放一段时间后就会挂起。
我希望多个任务使用相同的 ssh 会话而不是创建新会话。为此,我pipelining = True在本地文件夹ansible.cfg和命令行中设置了以下内容。
cat /opt/automation/startservices/ansible.cfg
[defaults]
host_key_checking = False
gathering = smart
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=600s
control_path = %(directory)s/%%h-%%r
pipelining = True
ANSIBLE_SSH_PIPELINING=0 ansible-playbook -i /opt/automation/startservices/finalallmw.hosts /opt/automation/startservices/va_action.yml -e '{ dest_host: myremotehost7 }' -e dest_user=oracle
Run Code Online (Sandbox Code Playgroud)
该剧本太大,无法在此处共享,但正是该任务循环,并且由于 60 秒内超过 20 个 ssh 连接而挂起。
cat /opt/automation/startservices/ansible.cfg
[defaults]
host_key_checking = False
gathering = smart
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=600s
control_path = %(directory)s/%%h-%%r
pipelining = True
ANSIBLE_SSH_PIPELINING=0 …Run Code Online (Sandbox Code Playgroud)