执行一个本地脚本并传参数

执行一个本地脚本并传参数

playbook方式

# a.shuptimeecho $1# a.sh 就在这个playbook的同级目录- hosts: 10.10.1.72 tasks: – name: exe #shell: /home/gcpadmin/ansible_work/adhoc/a.sh script: a.sh xx register: aa – debug: msg: “{{ aa.stdout }}”

role方式

drwxrwxr-x. 2 gcpadmin gcpadmin 21 Aug 12 15:06 defaultsdrwxrwxr-x. 2 gcpadmin gcpadmin 17 Aug 12 15:23 filesdrwxrwxr-x. 2 gcpadmin gcpadmin 21 Aug 12 11:31 handlersdrwxrwxr-x. 2 gcpadmin gcpadmin 21 Aug 12 11:31 meta-rw-rw-r–. 1 gcpadmin gcpadmin 1328 Aug 12 11:31 README.mddrwxrwxr-x. 2 gcpadmin gcpadmin 66 Aug 12 15:23 tasksdrwxrwxr-x. 2 gcpadmin gcpadmin 37 Aug 12 11:31 testsdrwxrwxr-x. 2 gcpadmin gcpadmin 21 Aug 12 11:31 varsfiles/ 下有a.sh tasks如下:- name: exe script: a.sh xx register: aa- debug: msg: “{{ aa.stdout }}”$ansible-playbook test.ymlPLAY [10.xxxx] **************************************************************************************************TASK [vmware.provisning.disk : exe] ********************************************************************************changed: [10.xxxx]TASK [vmware.provisning.disk : debug] ******************************************************************************ok: [10.xxxx] => { “msg”: ” 15:24:38 up 4:50, 2 users, load average: 0.00, 0.01, 0.04\r\nxx\r\n”}PLAY RECAP *********************************************************************************************************1xxxx : ok=2 changed=1 unreachable=0 failed=0