如何在Ansible YAML文件上接收参数变量
我正在尝试使用Ansible在节点计算机上自动安装Oracle RPatch文件。这里的问题是,我需要继续通过Ansible手动传递补丁ID。有没有办法将补丁id作为参数传递? 谢谢你抽出时间。 这是我正在编写的代码示例,以便您更好地识别我试图替换的内容如何在Ansible YAML文件上接收参数变量,ansible,Ansible,我正在尝试使用Ansible在节点计算机上自动安装Oracle RPatch文件。这里的问题是,我需要继续通过Ansible手动传递补丁ID。有没有办法将补丁id作为参数传递? 谢谢你抽出时间。 这是我正在编写的代码示例,以便您更好地识别我试图替换的内容 --- - hosts: web #group of hosts on host file remote_user: client become: yes #become super SU tasks: - name: Te
---
- hosts: web #group of hosts on host file
remote_user: client
become: yes #become super SU
tasks:
- name: Test Host Connection
ping:
- name: Copy Opatch zipfile to the Target Oracle_home
copy:
src: #substitute for the oracle orpatch file
dest: /tmp
- name: Upgrade Rpatch
shell: unzip -o /tmp/p6880880_112000_Linux-x86-64.zip -d $ORACLE_HOME #default is /u01/oracle/11204
register: unzip
- name: Define Retail Home Path
shell: export RETAIL_HOME = </u01/app/rms>
- name: Move to Retail_Home Directory
shell: cd $RETAIL_HOME
- name: execute rpatch to analyse the Patch
shell: orpatch analyze -s /tmp/patch_id #define here the patch__id
- name: ORPatch Apply
shell: orpatch apply
- name: List the Inventory
shell: orpatch lsinventory
你要找的是剧本变量。我建议您阅读,因为这将使您熟悉使用变量的不同方式。但是我将展示一种在命令行上传递它的方法 下面的示例将patch_id设置为模板化变量。它还通过强制过滤器运行它,如果未设置,则所需的playbook将提前失败
---
- hosts: web #group of hosts on host file
remote_user: client
become: yes #become super SU
tasks:
- name: Test Host Connection
ping:
- name: Copy Opatch zipfile to the Target Oracle_home
copy:
src: #substitute for the oracle orpatch file
dest: /tmp
- name: Upgrade Rpatch
shell: unzip -o /tmp/p6880880_112000_Linux-x86-64.zip -d $ORACLE_HOME #default is /u01/oracle/11204
register: unzip
- name: Define Retail Home Path
shell: export RETAIL_HOME = </u01/app/rms>
- name: Move to Retail_Home Directory
shell: cd $RETAIL_HOME
- name: execute rpatch to analyse the Patch
shell: orpatch analyze -s /tmp/{{ patch_id | mandatory }}
- name: ORPatch Apply
shell: orpatch apply
- name: List the Inventory
shell: orpatch lsinventory
希望这有帮助 我认为CLI变量和值应该用双引号引起来。不是吗?patch_Id=mypatchid应该在双引号之间,对吗?
ansible-playbook -i myinventory -e patch_id=mypatchid myplaybook.yaml