在主机A中运行剧本以获取价值并将其传递给在本地执行的任务

时间:2019-05-20 15:57:57

标签: ansible ansible-2.x

执行任务以在Windows计算机中获取主机名,并将其存储在名为HstName的变量中。然后,我必须使用变量在GCP中动态创建文件夹。我的GCP模块仅适用于localhost

Ansible版本:2.7

任务1:定位主机窗口,以获取主机名 任务2:“ gcp_storage”模块使用localhost在存储桶中创建对象。

 hosts: win
  gather_facts: no
  serial: 1
  connection: winrm
  become_method: runas
  become_user: admin
  vars:
    ansible_become_password: '}C7I]8zH@5cPDE8'
    gcp_object: "gcp-shareddb-bucket/emeraldpos/stage/"

  tasks:
  - name: hostname
    win_command: hostname
    register: Hstname

  - set_fact:
      Htname: "{{ Hstname.stdout | trim}}"

  - debug:
      msg: "{{Htname}}"

- hosts: localhost
  gather_facts: no

  tasks:
  - name: Create folder under EMERALDPOS
    gc_storage:
      bucket: gcp-shareddb-bucket
      object: "{{gcp_object}}{{Htname}}"
      mode: create
      region: us-west2
      project: sharedBucket-228905
      gs_access_key: "NAKJSAIUS231219237LOKM"
      gs_secret_key: "XABSAHSKASAJS:OAKSAJNDADIAJAJD:N<MNMN"

Ansible应该在gcp存储对象中创建gcp-shareddb-bucket / emeraldpos / stage / HOSTNAME

0 个答案:

没有答案