2016-11-06 77 views
0

我写的ansible剧本将:Ansible:无法存取寄存器的值

  1. 登录到Windows中,如果
  2. 检查我正在部署的应用程序的版本已经存在
  3. 下载应用从混帐
  4. 提取应用程序的zip文件
  5. 它移动到正确的目录

我在一段代码中遇到了一堆麻烦,我需要找到提取的目录。我解压GIT压缩文件,当然,通过Github压缩文件包含git哈希目录。我所做的是我通过一个简单的find-like命令在windows中寻找这个目录。问题是,在调试过程中,我可以看到stdout_lines中的结果......但实际上,它似乎不起作用。

下面是代码:

--- 
# Register our work path to do work in 
- name: Registering {{apm_work_path}} as our working path 
    tags: install 
    win_stat: path={{apm_work_path}} 
    register: my_apmworkpath 

# First check to see if an agent is already installed in our 
# destination. We want to make sure we dont install multiple 
# agents 
- name: Checking if {{apm_root_path}} path exists on our remote server 
    tags: install 
    win_stat: path={{apm_root_path}} 
    register: my_apmrootpath 

# Check if the apm agent is installed in the root path 
- name: Checking if {{apm_root_path}}\\{{apm_install_path}} path exists 
    tags: install 
    win_stat: path={{apm_root_path}}/{{apm_install_path}} 
    register: my_apminstallpath 

# Check if the apm version is installed in the root path 
- name: Checking if {{apm_version}} path exists 
    tags: install 
    win_stat: path={{apm_root_path}}\\{{apm_install_path}}\\{{apm_version}} 
    register: my_apmversionpath 

# We also want to make sure that we keep track of the path 
# that we want our agent to be placed 
- name: An agent already exists on server 
    tags: install 
    debug: msg="APM {{apm_version}} is already installed under {{apm_install_path}}" 
    when: my_apminstallpath.stat.exists == true 

# Create our work directory 
- name: Creating Work directory 
    tags: install 
    win_file: path={{apm_work_path}} state=directory mode=0755 
    when: my_apmworkpath.stat.exists == false 

# Create our application directory 
- name: Creating APM Agent directory 
    tags: install 
    win_file: path={{apm_root_path}}\\{{apm_install_path}} state=directory mode=0755 
    when: my_apminstallpath.stat.exists == false 

# Create our versioning directory 
- name: Create APM version directory 
    tags: install 
    win_file: path={{apm_root_path}}\\{{apm_install_path}}\\{{apm_version}} state=directory mode=0775 
    when: my_apmversionpath.stat.exists == false 

# Export our agent from our version control repo (GIT) 
- name: Exporting Agent from GIT 
    tags: install 
    win_get_url: 
    url: http://git.sys.a.com/APM/apm-agent-{{apm_version}}-base-win/repository/archive.zip?ref=master 
    dest: "{{apm_work_path}}\\agent.zip" 
    when: my_apmversionpath.stat.exists == false 

# Make sure we succesfully got our agent downloaded 
- name: Checking our agent download 
    tags: install 
    win_stat: path={{apm_work_path}}\\agent.zip 
    register: my_agentarchive 

# Create the base-nix directory 
- name: Creating base-nix directory 
    tags: install 
    win_file: path={{apm_root_path}}\\{{apm_install_path}}\\{{apm_version}}\\base-win state=directory mode=0755 
    when: 
    - my_apmversionpath.stat.exists == false 
    - my_agentarchive.stat.exists == true 

# Extract our GIT tarball to our new directory 
- name: Extracting Agent 
    tags: install 
    win_unzip: 
     src: "{{apm_work_path}}\\agent.zip" 
     dest: "{{apm_work_path}}" 
     rm: True 
    when: 
    - my_apmversionpath.stat.exists == false 
    - my_agentarchive.stat.exists == true 

############################################################### 
##### THIS SECTION ############################################ 
# Get the extract directory 
- name: Locate the Extracted Directory 
    tags: install 
    win_shell: for /d %d in (*apm-agent*) do echo %d 
    args: 
     executable: cmd 
     chdir: "{{apm_work_path}}" 
    register: extout 

###### UNABLE TO SEE RESULTS HERE ############ 
- debug: msg={{ item }} 
    with_items: extout.stdout_lines 

# Copy data from our work directory to the base-win directory 
- name: Migrate Agent Files 
    tags: install 
    win_copy: 
     src: "{{apm_work_path}}\\{{ item }}\\" 
     dest: "{{apm_root_path}}\\{{apm_install_path}}\\{{apm_version}}\\base-win" 
    with_items: 
     extout.stdout_lines 
    ignore_errors: no 
    when: 
    - my_apmversionpath.stat.exists == false 
    - my_agentarchive.stat.exists == true 

# Now create a symbolic link for the agent path 
- name: Creating Symlink 
    tags: install 
    win_file: src={{apm_root_path}}\\{{apm_install_path}}\\{{apm_version}}\\base-win dest={{apm_root_path}}\\{{apm_install_path}}\\base-win state=link 
    when: 
    - my_apmversionpath.stat.exists == false 
    - my_agentarchive.stat.exists == true 

# And cleanup after ourselves 
#- name: Removing downloaded files 
# tags: install 
# win_file: path={{apm_work_path}} state=absent 
# when: 
# - my_apmversionpath.stat.exists == false 
# - my_agentarchive.stat.exists == true 

相关章节

############################################################### 
##### THIS SECTION ############################################ 
# Get the extract directory 
- name: Locate the Extracted Directory 
    tags: install 
    win_shell: for /d %d in (*apm-agent*) do echo %d 
    args: 
     executable: cmd 
     chdir: "{{apm_work_path}}" 
    register: extout 

###### UNABLE TO SEE RESULTS HERE ############ 
- debug: msg={{ item }} 
    with_items: extout.stdout_lines 

我可以看到我的注册

changed: [ciwsdbxd8559.silver.com] => { 
    "changed": true, 
    "cmd": "for /d %d in (*apm-agent*) do echo %d", 
    "delta": "0:00:00.062173", 
    "end": "2016-11-06 07:56:51.816995", 
    "invocation": { 
     "module_name": "win_shell" 
    }, 
    "rc": 0, 
    "start": "2016-11-06 07:56:51.754822", 



    "stderr": "", 
    "stdout": "\r\nE:\\SA\\tmp\\apm>echo apm-agent-10.3.0.15-base-win-master-541edbf478cc5e960c33e90b394a9b9cd822def3 \r\napm-agent-10.3.0.15-base-win-master-541edbf478cc5e960c33e90b394a9b9cd822def3\r\n", 
    "stdout_lines": [ 
     "", 
     "E:\\SA\\tmp\\apm>echo apm-agent-10.3.0.15-base-win-master-541edbf478cc5e960c33e90b394a9b9cd822def3 ", 
     "apm-agent-10.3.0.15-base-win-master-541edbf478cc5e960c33e90b394a9b9cd822def3" 
    ], 
    "warnings": [] 
} 

但是下面的调试命令GIV的值es我以下内容:

TASK [../roles/apm_windows : debug] ******************************************** 
task path: /home/SILVER/c53259/ansible/apm_deployment/roles/apm_windows/tasks/agent.yml:95 
ok: [ciwsdbxd8559.silver.com] => (item=extout.stdout) => { 
    "invocation": { 
     "module_args": { 
      "msg": "extout.stdout" 
     }, 
     "module_name": "debug" 
    }, 
    "item": "extout.stdout", 
    "msg": "extout.stdout" 
} 

对发生了什么有什么想法?

使用Ansible 2.2 的Python 2.7

+0

您可以发布代码的相关部分而不是整个代码吗? – helloV

+0

你好。我添加了一个注释块,指出相关部分,但是我会提取它以使其更加突出。 –

回答

1

你确定这个工程没有一个错误?因为mesg在调试中不是有效的选项。你的意思是msg

- debug: mesg={{ item }} 

无论如何,问题是你使用了一个错误的参数。因为您正在打印变量的值,所以请使用var

- debug: var={{ item }} 
    with_items: extout.stdout_lines 
+0

对不起,我的代码有味精,但我认为我的拼写检查做了一些大声笑。我会给你一个镜头!感谢您及时的回复。 –

+0

这个伎俩!很简单。再次感谢您的帮助 –