首页 文章

Ansible:无法访问Register VAlue

提问于
浏览
0

我正在写一本安息书,它将:

  • 登录到Windows框中

  • 检查我正在部署的应用程序的版本是否已存在

  • 从git下载应用程序

  • 提取应用程序的zip文件

  • 将其移动到正确的目录

我在代码的一部分遇到麻烦,我需要找到解压缩的目录 . 我正在提取GIT zip,当然,通过Github,zip文件包含git哈希目录 . 我所做的是通过Windows中的简单find-like命令查找此目录 . 问题是在调试期间,我可以在stdout_lines中看到结果......但实际上,它似乎不起作用 .

Here is the code:

---
# 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

Relevant Section

###############################################################
##### 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": []
}

但是,以下调试命令为我提供了以下内容:

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

1 回答

  • 1

    你确定这没有错误吗?因为 mesg 在调试中不是有效选项 . 你的意思是 msg

    - debug: mesg={{ item }}
    

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

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

相关问题