我需要将文件格式机A复制到机器B,而我运行所有安全任务的控制机器是机器C(本地机器)
我尝试过以下方法:
在ansible的shell模块中使用scp命令
hosts: machine2
user: user2
tasks:
- name: Copy file from machine1 to machine2
shell: scp user1@machine1:/path-of-file/file1 /home/user2/file1
Run Code Online (Sandbox Code Playgroud)
这种方法一直持续下去.
使用获取和复制模块
hosts: machine1
user: user1
tasks:
- name: copy file from machine1 to local
fetch: src=/path-of-file/file1 dest=/path-of-file/file1
hosts: machine2
user: user2
tasks:
- name: copy file from local to machine2
copy: src=/path-of-file/file1 dest=/path-of-file/file1
Run Code Online (Sandbox Code Playgroud)
这种方法给我一个错误如下:
error while accessing the file /Users/<myusername>/.ansible/cp/ansible-ssh-machine2-22-<myusername>, error was: [Errno 102] Operation not supported on socket: u'/Users/<myusername>/.ansible/cp/ansible-ssh-machine2-22-<myusername>'
Run Code Online (Sandbox Code Playgroud)
任何的意见都将会有帮助.
我使用标签来跟踪我的EC2实例,例如(项目,环境).我有一个用例,我只需要过滤那些属于特定项目和特定环境的实例.
当我使用带有boto的过滤器并传递这两个值时,我得到的结果是OR而不是过滤器的AND,所以我收到属于不同项目但是环境相同的实例列表.
现在我可以使用两个列表,然后比较每个列表中的实例并获得所需的实例集,但有没有更好的方法来完成此操作?
这是我在做的事情:
conn = ec2.EC2Connection('us-east-1',aws_access_key_id='XXX',aws_secret_access_key='YYY')
reservations = conn.get_all_instances(filters={"tag-key":"project","tag-value":<project-name>,"tag-key":"env","tag-value":<env-name>})
instances = [i for r in reservations for i in r.instances]
Run Code Online (Sandbox Code Playgroud)
现在,我获取的实例列表给出了指定项目中的所有实例,而不管环境和指定环境中的所有实例,无论项目如何.
以下是存储在同一文件夹中的两个shell脚本,两个脚本都具有执行权限:
shell1.sh
#!/bin/bash
exec shell2.sh
Run Code Online (Sandbox Code Playgroud)
shell2.sh
#!/bin/bash
pwd
Run Code Online (Sandbox Code Playgroud)
尝试执行shell1.sh时收到以下错误:
./shell1.sh: line 3: exec: shell2.sh: not found
Run Code Online (Sandbox Code Playgroud)
有什么我做错了吗?这适用于其他机器,但只是在一个特定的服务器中它无法正常工作.
任何的意见都将会有帮助.