How to run apt update and upgrade via Ansible shell

I wouldn’t recommend using shell for this, as Ansible has the apt module designed for just this purpose. I’ve detailed using apt below. In a playbook, you can update and upgrade like so: – name: Update and upgrade apt packages become: true apt: upgrade: yes update_cache: yes cache_valid_time: 86400 #One day The cache_valid_time value can … Read more

Missing sudo password in Ansible

Try with the option -kK. It will prompt for password. $ ansible-playbook mail.yml -kK SSH password: BECOME password[defaults to SSH password]: -k, –ask-pass: ask for connection password -K, –ask-become-pass: ask for privilege escalation password

Not possible to source .bashrc with Ansible

You have two options to use source with ansible. One is with the “shell:” command and /bin/sh (the ansible default). “source” is called “.” in /bin/sh. So your command would be: – name: source bashrc sudo: no shell: . /home/username/.bashrc && [the actual command you want run] Note you have to run a command after … Read more

How to get an arbitrary remote user’s home directory in Ansible?

Ansible (from 1.4 onwards) already reveals environment variables for the user under the ansible_env variable. – hosts: all tasks: – name: debug through ansible.env debug: var=ansible_env.HOME Unfortunately you can apparently only use this to get environment variables for the connected user as this playbook and output shows: – hosts: all tasks: – name: debug specified … Read more

How to copy files with ansible relatively to the role?

If you do not provide any path at all, just the filename, Ansible will pick it automatically from the files directory of the role. – copy: src: foo.conf dest: /etc/foo.conf Additionally, since Ansible 1.8, there is the variable role_path which you could use in your copy task. – copy: src: “{{ role_path }}/files/foo.conf” dest: /etc/foo.conf

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)