How to create folder in $USER $HOME using Ansible -
i'm new ansible trying become $user create .ssh folder inside $home directory , i'm getting permission denied:
--- - hosts: amazon gather_facts: false vars: ansible_python_interpreter: "/usr/bin/env python3" account: 'jenkins' home: "{{out.stdout}}" tasks: - name: create .ssh directory become: true become_method: sudo become_user: "{{account}}" shell: "echo $home" register: out - file: path: "{{home}}/.ssh" state: directory my output is:
macbook-pro-60:playbooks stefanov$ ansible-playbook variable.yml -v using /users/stefanov/.ansible/ansible.cfg config file play [amazon] ************************************************************************************************************************************************************************************* task [create .ssh directory] ********************************************************************************************************************************************************************** changed: [slave] => {"changed": true, "cmd": "echo $home", "delta": "0:00:00.001438", "end": "2017-08-21 10:23:34.882835", "rc": 0, "start": "2017-08-21 10:23:34.881397", "stderr": "", "stderr_lines": [], "stdout": "/home/jenkins", "stdout_lines": ["/home/jenkins"]} task [file] *************************************************************************************************************************************************************************************** fatal: [slave]: failed! => {"changed": false, "failed": true, "msg": "there issue creating /home/jenkins/.ssh requested: [errno 13] permission denied: b'/home/jenkins/.ssh'", "path": "/home/jenkins/.ssh", "state": "absent"} retry, use: --limit @/users/stefanov/playbooks/variable.retry play recap **************************************************************************************************************************************************************************************** slave : ok=1 changed=1 unreachable=0 failed=1 i'm guessing - name , - file dicts , considered different tasks.
, executed in - name no longer valid in - file?
because switched jenkins user in - name , in - file i'm account ssh.
then how can concatenate both tasks in one?
right way this?
another thing how can sudo file module? can't see such option:
http://docs.ansible.com/ansible/latest/file_module.html
or should shell: mkdir -pv $home/.ssh instead of using file module?
then how can concatenate both tasks in one?
you cannot it, can add become second task, make run same permissions first one:
- file: path: "{{home}}/.ssh" state: directory become: true become_method: sudo become_user: "{{account}}" another thing how can sudo file module can't see such option
because become (and other) not parameter of module, general declaration task (and play).
i'm guessing -name , -file dicts , considered different tasks.
the first task shell, not name. can add name task (just become).
Comments
Post a Comment