Run the new playbook in
“check” mode. This mode will run the code, but won't actually do the actions.
ansible-playbook doc-files.yml --check
PLAY [My first playbook] ****************************************************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [repo.cloudclub.edu]
TASK [docs : Create a directory] ********************************************************************************************************************************************************************************
fatal: [repo.cloudclub.edu]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (ansible.builtin.file) module: user. Supported parameters include: _diff_peek, _original_basename, access_time, access_time_format, attributes, follow, force, group, mode, modification_time, modification_time_format, owner, path, recurse, selevel, serole, setype, seuser, src, state, unsafe_writes (attr, dest, name)."}
PLAY RECAP ******************************************************************************************************************************************************************************************************
repo.cloudclub.edu : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Oops! It looks like we found an error. Let's fix it.
“msg”: “Unsupported parameters for (ansible.builtin.file) module: user.
Modify the docs/tasks/main.yml file to change 'user:' to 'owner:' and run the playbook again.
ansible-playbook doc-files.yml --check
PLAY [My first playbook] ****************************************************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [repo.cloudclub.edu]
TASK [docs : Create a directory] ********************************************************************************************************************************************************************************
changed: [repo.cloudclub.edu]
TASK [docs : Create an empty file in the new directory] *********************************************************************************************************************************************************
changed: [repo.cloudclub.edu]
PLAY RECAP ******************************************************************************************************************************************************************************************************
repo.cloudclub.edu : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
It looks like we fixed it.
Add and commit the changes
Run the playbook again
without check modeansible-playbook doc-files.yml
PLAY [My first playbook] ****************************************************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [repo.cloudclub.edu]
TASK [docs : Create a directory] ********************************************************************************************************************************************************************************
fatal: [repo.cloudclub.edu]: FAILED! => {"changed": false, "msg": "There was an issue creating /opt/docs as requested: [Errno 13] Permission denied: b'/opt/docs'", "path": "/opt/docs"}
PLAY RECAP ******************************************************************************************************************************************************************************************************
repo.cloudclub.edu : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Oops! Another error - See the task it failed on “TASK [docs | Create a directory ]” and the error itself -There was an issue creating /opt/docs as requested: [Errno 13] Permission denied: b'/opt/docs
Update the main.yml file - add “become: true” to the bottom of the task like this.
Be sure to “outdent” the line.
group: nobody
mode: '0400'
become: true
Run the playbook again
Yet another error. This time it's asking about the sudo password. Why? Because we added the “become: true” line. We told it to use sudo, but didn't give it a password to use.
Run the playbook again, but add these 2 options
Options:
========
-k = ask ssh password
-K = ask sudo/become password
New command:
=============
ansible-playbook doc-files.yml -kK
ansible-playbook doc-files.yml -kK
SSH password:
BECOME password[defaults to SSH password]:
PLAY [My first playbook] ****************************************************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [repo.cloudclub.edu]
TASK [docs : Create a directory] ********************************************************************************************************************************************************************************
changed: [repo.cloudclub.edu]
TASK [docs : Create an empty file in the new directory] *********************************************************************************************************************************************************
fatal: [repo.cloudclub.edu]: FAILED! => {"changed": false, "msg": "Error, could not touch target: [Errno 13] Permission denied: b'/opt/docs/git-notes.txt'", "path": "/opt/docs/git-notes.txt"}
PLAY RECAP ******************************************************************************************************************************************************************************************************
repo.cloudclub.edu : ok=2 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
We fixed the error for creating the directory, but we're failing to create the empty file. Why?
Whom are we running the playbook as? YOU! – More specifically, your user account that you loged into the ansible server with.
What is the ownership and permissions of the directory? – Owner: nobody – Group: nobody – Permissions: read-only for the owner and nothing for everyone elsae.
Update the main.yml file to fix these things
Run the playbook again - Success!!
ansible-playbook doc-files.yml -kK
SSH password:
BECOME password[defaults to SSH password]:
PLAY [My first playbook] ****************************************************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [repo.cloudclub.edu]
TASK [docs : Create a directory] ********************************************************************************************************************************************************************************
changed: [repo.cloudclub.edu]
TASK [docs : Create an empty file in the new directory] *********************************************************************************************************************************************************
changed: [repo.cloudclub.edu]
PLAY RECAP ******************************************************************************************************************************************************************************************************
repo.cloudclub.edu : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
What does the file ownership and permission look like now? – System default, since we didn't specify them in our task to create the file.