asked on
Ansible Playbook mount CIFS, copy and run shell script
Hello,
I am having some issues with the following playbook that runs in linux. I've added a part to mount a cifs share, copy the script and the run it locally.
Getting the following error:
JSON: Expecting value: line 1 column 1 (char 0)
Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/home/ansible/ubuntus.yml': line 20, column 15, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Mount network share
mount:
^ here
---
- hosts: all
become: true
vars:
uri: "//auto01.nal.com/auto_hq_ds01/v/Tan/Ub/"
username: "lxx@al.com"
password: "XXX"
mountpoint: "/share"
tasks:
- name: Join the machine if it is not already on the domain.
become: yes
command: /opt/pbis/bin/domainjoin-cli join --ou OU=bolt,DC=ev,DC=nal,DC=com ev.nal.com jdom XXX
no_log: True
- name: Allow {{ reqUser }} to sudo, and validate the sudoers file before saving
#- set_fact: reqUser="{{ lookup('env','requestedBy') }}"
ansible.builtin.lineinfile:
path: "/etc/sudoers.d/90-cloud-init-users"
state: present
mode: 0440
create: yes
regexp: '^corp\\{{ reqUser }}'
line: 'orp\\{{ reqUser }} ALL=(ALL) NOPASSWD: ALL'
validate: /usr/sbin/visudo -cf %s
- name: utility present
ansible.builtin.package:
name: cifs-utils
state: present
- name: Mount network share
ansible.posix.mount:
src: "{{ uri }}"
path: "{{ mountpoint }}"
fstype: cifs
opts: 'username={{ username }},password={{ password }}'
state: mounted
- name: Copy data
copy:
src: //auto01.nal.com/auto_hq_ds01/v/Tan/Ub/install_tanium_ubuntu.sh
dest: /opt/ mode=0755
remote_src: yes
- name: "Execute the script"
command: bash /opt/install_t_ubuntu.sh
register: version
Can someone please help?
Thank you
ASKER
Hi Simon,
This is the latest revision.
The error appears to be in '/home/ansible/ubuntuscript.yml': line 19, column 15, but may
be elsewhere in the file depending on the exact syntax problem.
The line reference it's a little different in Visual Studio Code than here. The error complains about line 19 which is
Any thoughts on how to should I define this?
Thank you so much!
---
- hosts: all
become: true
tasks:
- name: Join the machine if it is not already on the domain.
become: yes
command: /opt/pbis/bin/domainjoin-cli join --ou OU=bolt,DC=ev,DC=nal,DC=com ev.nal.com dom xxxx
no_log: True
- name: Allow {{ reqUser }} to sudo, and validate the sudoers file before saving
ansible.builtin.lineinfile:
path: "/etc/sudoers.d/90-cloud-init-users"
state: present
mode: "0440"
create: yes
regexp: '^corp\\{{ reqUser }}'
line: 'corp\\{{ reqUser }} ALL=(ALL) NOPASSWD: ALL'
validate: /usr/sbin/visudo -cf %s
- name: Mount network share
mount:
src: //auto_hq00cifs_ds01.orp.nal.com/auto_cifs_ds01/8/um/tu/
path: /mnt
fstype: cifs
opts: 'username=admin@corp.nal.com,password=XXX'
state: mounted
become: true
- name: Copy data
copy:
src: //auto_hq00cifs_ds01.orp.nal.com/auto_cifs_ds01/8/um/tu/install_tanium_ubuntu.sh
dest: /opt/
mode: "0755"
remote_src: yes
- name: "Execute the script"
command: bash /opt/install_tanium_ubuntu.sh
register: version
I'm doing this on my phone on a walk, so may be misreading it!
ASKER
Thanks Simon! I made the change and testing now.
ASKER
That seemed to have worked, however the playbook errors out with
TASK [Mount network share] *****************************************************,fatal: [tan3]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (mount) module: become. Supported parameters include: src, path (name), dump, passno, fstab, boot, fstype, state, backup, opts."},,PLAY RECAP *********************************************************************,tan3 : ok=3 changed=2 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
ASKER
Ok, "become" it's now indented this way... testing now.
- name: Mount network share
mount:
src: //cifs_ds01.orp.nal.com/auto_cifs_ds01/8/ium/tu/
path: /mnt
fstype: cifs
opts: 'username=dmin@op.nal.com,password=XXX'
state: mounted
become: true
Thanks!
ASKER
Looks like I am still getting the error:
TASK [Mount network share] *****************************************************,fatal: [tan6]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (mount) module: become. Supported parameters include: src, path (name), dump, passno, fstab, boot, fstype, state, backup, opts."},,PLAY RECAP *********************************************************************,tan6 : ok=3 changed=2 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
ASKER
Let me double check the modify date for the yaml file.
ASKER
Ok, so the time stamp was old looks like the VPN timed out and it was not updated.
With the latest changes I am getting the following:
TASK [Mount network share] *****************************************************,fatal: [tan7]: FAILED! => {"changed": false, "msg": "Error mounting /mnt: mount: /mnt: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.\n"},,PLAY RECAP *********************************************************************,tan7 : ok=3 changed=2 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
ASKER
Looks like I might need to install CIFS-utils first?
sudo apt install cifs-utils
ASKER
Maybe adding something like this?
tasks:
- name: Execute command using the shell module
become: true
become_user: root
shell: sudo apt install cifs-utils
apt install -y cifs-utils
ASKER
Ok, thanks, testing now...
- name: Install cifs-utils to get the mount.cifs program
package:
name: cifs-utils
state: present
ASKER
That sounds much better, I've updated the play with that, fingers crossed!
ASKER
Thanks so much for pointing and explaining that out!
ASKER
This is weird, getting the following:
Unable to validate syntax for Playbook(s). Failed to execute script on host hq00ansvrap01. Error: [WARNING]: While constructing a mapping from /home/ansible/ubuntuscript.yml,
line 5, column 8, found a duplicate dict key (name). Using last defined value
only.
ERROR! conflicting action statements: package, state
The offending line appears to be:
tasks:
- name: Install cifs-utils to get the mount.cifs program
^ here
ASKER
Sure, I just did.
ASKER
Ok, looks that the above might have worked!
Getting closer, I hope :)
Next looks like it can't find "install_tanium_ubuntu.sh" but I know it's there...
TASK [Copy data] ***************************************************************,fatal: [tan12]: FAILED! => {"changed": false, "msg": "Source //auto_hq00cifs_ds01.orp.nal.com/auto_cifs_ds01/8/um/tu/install_tanium_ubuntu.sh not found"},,PLAY RECAP *********************************************************************,tan12 : ok=5 changed=4 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
ASKER
All right...so I've manually tested the steps and they seem to be working fine when I use the following:
root@tan12:~# sudo mount.cifs //auto_hq00cifs_ds01.internal.com/auto_hq00cifs_ds01/vRA8/Tanium/Ubuntu /mnt/share/ -o user=admin@corp.adcinternal.com,pass=IloveBCN123!
root@tan12:~# cd share
-bash: cd: share: No such file or directory
root@tan12:~# cd /mnt
root@tan12:/mnt# ls
Something isn't working with the copy part.
Play:
- name: Allow {{ reqUser }} to sudo, and validate the sudoers file before saving
ansible.builtin.lineinfile:
path: "/etc/sudoers.d/90-cloud-init-users"
state: present
mode: "0440"
create: yes
regexp: '^corp\\{{ reqUser }}'
line: 'corp\\{{ reqUser }} ALL=(ALL) NOPASSWD: ALL'
validate: /usr/sbin/visudo -cf %s
- name: Mount network share
mount:
src: //auto_hq00cifs_ds01.orp.nal.com/auto_cifs_ds01/8/um/tu/
path: /mnt
fstype: cifs
opts: 'username=admin@corp.nal.com,password=XXX'
state: mounted
become: true
- name: Copy data
copy:
src: //auto_hq00cifs_ds01.orp.nal.com/auto_cifs_ds01/8/um/tu/install_tanium_ubuntu.sh
dest: /opt/
mode: "0755"
remote_src: yes
- name: "Execute the script"
command: bash /opt/install_tanium_ubuntu.sh
register: version
Also, in the "copy" section, you should replace
src: //auto_hq00cifs_ds01.orp.nal.com/auto_cifs_ds01/8/um/tu/install_tanium_ubuntu.sh
with
src: /mnt/install_tanium_ubuntu.sh
Or, miss out the "copy" tasks completely, and run the command as "bash /mnt/install_tanium_ubuntuASKER
Sorry! For some reason the copy/paste sometimes doesn't seem to keep the spaces in place. I've updated post above.
I have also change the src with your suggestion.
Testing!
ASKER
Simon, thank you so much for the help, the teaching and the patience! :)
ASKER
Thanks Simon! I am testing now…