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

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

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

playbook方式

# a.sh
uptime
echo $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 defaults
drwxrwxr-x. 2 gcpadmin gcpadmin 17 Aug 12 15:23 files
drwxrwxr-x. 2 gcpadmin gcpadmin 21 Aug 12 11:31 handlers
drwxrwxr-x. 2 gcpadmin gcpadmin 21 Aug 12 11:31 meta
-rw-rw-r--. 1 gcpadmin gcpadmin 1328 Aug 12 11:31 README.md
drwxrwxr-x. 2 gcpadmin gcpadmin 66 Aug 12 15:23 tasks
drwxrwxr-x. 2 gcpadmin gcpadmin 37 Aug 12 11:31 tests
drwxrwxr-x. 2 gcpadmin gcpadmin 21 Aug 12 11:31 vars


files/ 下有a.sh

tasks如下:
- name: exe
script: a.sh xx
register: aa

- debug:
msg: "{{ aa.stdout }}"

$ansible-playbook test.yml

PLAY [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