我想执行 shell 命令,例如:使用 Ansible 在正在运行的 docker 容器内执行“wget”命令。这是我试图执行的剧本
---
- name: Enter into a running container and run a command
docker_container:
name: centos_conatainer
state: started
image: centos
command: wget https://downloadlink.com
Run Code Online (Sandbox Code Playgroud)
这会停止容器,并且它也不会下载文件。这是使用 docker_container 模块执行 shell 命令的正确方法,还是有其他方法可以使用 Ansible 执行此操作?
这是我的JSON对象
{
"master": {
"node": "xyz",
"files": [{"type": "modified", "file": "test.txt"}]
},
"testbranch2": {
"node": "abc",
"files": [{"type": "modified", "file": "test.txt"}]
},
"testbranch": {
"node": "xxx",
"files": [{"type": "modified", "file": "test.txt"}],
}
}
Run Code Online (Sandbox Code Playgroud)
我只需要对象键名称,如"master","testbranch2","testbranch.我如何使用groovy只获取对象键名?
我的目的是在不同的主机中执行每个角色.我正在做一个简单的任务,在每个主机上下载文件.我有一个看起来像这样的主机文件
[groupa]
10.0.1.20
[groupb]
10.0.1.21
Run Code Online (Sandbox Code Playgroud)
下面是我的main_file.yml文件
---
- hosts: local
connection: local
gather_facts: no
roles:
- oracle
- apache
Run Code Online (Sandbox Code Playgroud)
我的角色结构
main_file.yml
roles
|-- oracle
| |-- tasks
| |-- main.yml
| |-- download_file.yml
|-- apache
| |-- tasks
| |-- main.yml
| |-- download_file.yml
Run Code Online (Sandbox Code Playgroud)
ORACLE/main.yml
---
- name: downloading a file in groupa
hosts: groupa
tasks:
- include: tasks/download_file.yml
Run Code Online (Sandbox Code Playgroud)
ORACLE/download_file.yml
---
- name: download file
shell: wget http://dummyurl.com/random.sh
Run Code Online (Sandbox Code Playgroud)
Apache角色遵循相同的步骤,但对于"groupb".但是当我执行main_file.yml时,我收到以下错误
ERROR! no action detected in task. This often indicates a misspelled …
Run Code Online (Sandbox Code Playgroud)