Ajitabh Pandey's Soul & Syntax

Exploring systems, souls, and stories – one post at a time

Tag: config-management

  • Ansible Quirks – 3

    I was running some playbook today and realise that the command line arguments of ansible-playbook do not behaves expected.

    My playbook has the following defined –

    remote_user: root

    When I issued the following command, my expectation was that the remote user name would be considered as specified by the “-u” option

    $ ansible-playbook -u centos -i '192.168.1.192,' play.yml

    However, this does not happen and the playbook still tries to connect as the user defined in the yml file.

    So, how do we override what is in the yml file through command line. The only way seems to be possible is using the -e or --extra-vars option as follows –

    $ ansible-playbook -e "ansible_ssh_user=centos ansible_ssh_private_key_file=~/.ssh/db_hosts_id_rsa " -i '192.168.1.192,' play.yml

  • Ansible Quirks – 2

    Today I tried to upgrade my ansible to 2.2 as I wanted to use the remote_src=yes feature from the unarchive module. My operating system on this machine is Linux Mint 17.3.

    I did –

    $ pip install --upgrade --user ansible

    and lo… I got the following error –

    ImportError: No module named packaging.version

    I next tried upgrading the pip itself and that also resulted in the same error. A bit of search on the internet did not help much as different ways worked for different people. So I decided to remove python-pip package and all that was installed along with it, reinstall pip and then try upgrading ansible. In short, following sequence of commands worked for me –

    
    $ rm -rf ~/.cache/pip/*
    $ python -m pip install -U --user pip
    $ sudo apt-get purge -y python-pip
    $ sudo apt-get autoremove
    $ sudo apt-get install python-dev
    $ python -m pip install --upgrade --user packaging
    $ python -m pip install --upgrade --user appdirs
    $ python -m pip install --upgrade --user ansible
    
  • Ansible Quirks – 1

    I started on the ansible learning path about 6 months or so back and have been writing my roles for deploying / configuring various systems I manage. Today while writing a template for sshd_config, I came across a point wherein the handler failed to restart the SSH service on the target server. Fortunately I was logged in as sudo on one of the terminals, and then I checked the config file generated and pushed by ansible. I found that the line

    PermitRootLogin {{ permit_root_login }}

    was translated to

    PermitRootLogin True

    . For a while I though that the variable I defined in

    defaults/main.yml

    was wrongly having a value of True instead of Yes, but I was wrong. Looking into some of the bugs filed in ansible I realised that this is the expected behaviour. The way to prevent strings like yes/no and true/false to be converted to True/False they have to be preceded with !!str in the variable definition. So the variable definition in my case would look like –

    permit_root_login: !!str Yes