bootstrapping ansible prerequisites with the script module. python required?

ansible

Solution

raw and scripts dont require python. I think the creates require python. To verify you can run

ansible -m script -a "ansible_prereqs.sh" 10.9.8.31 -vvvv

what you can do is shift the creates function to your script

#!/bin/sh
#install ansible prereqs manually or all apt-based ansible commands will fail
# http://euphonious-intuition.com/2013/01/bootstrapping-a-cluster-with-ansible-debian-6-and-oracle-java-7/
if [ ! -f /root/.ansible_prereqs_installed ]; then
        apt-get update
        apt-get install -y python python-apt python-pycurl sshpass
        touch /root/.ansible_prereqs_installed
        echo "CHANGE"
fi

And you can have your playbook something like this

tasks:
  -
    name: install ansible prerequisites
    script: ansible_prereqs.sh creates=/root/.ansible_prereqs_installed
    register: ans_preq
    changed_when: "'CHANGE' in ans_preq.stdout"

Hope that helps

Problem

Goal: Given a Debian server without python installed (and a few other missing ansible prerequisites), use ansible to get them installed so I can then use the normal ansible modules (almost all of which require python) to provision the server. According to the ansible documentation for the "script" module, "This module does not require python on the remote system, much like the raw module.". However, based on my tests, it seems like the script module does in fact attempt to run python on the remote system, at least if the `sudo` option is true. I believe I can get this to work with the script module as long as I don't enable ansible's `sudo` option, but then I need my remote user to have sudo permission without a password prompt or my script is just going to hang waiting for interactive entry of the sudo password. So my question is: A) What's the deal with the "script" module. Does it require python on the remote system or not? and B) Is there a better way to achieve my larger goal which is fully automated deployment without any manual steps before ansible itself can be used? Here's my output of `ansible-playbook -vvv` which shows clear it is running `/usr/bin/python` on the remote system, and there is no file there because python is not yet installed. ``` TASK: [install ansible prerequisites] ***************************************** <10.9.8.31> ESTABLISH CONNECTION FOR USER: plyons <10.9.8.31> EXEC ['ssh', '-C', '-tt', '-q', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/Users/plyons/.ansible/cp/ansible- ssh-%h-%p-%r', '-o', 'StrictHostKeyChecking=no', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications =gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'ConnectTimeout=10', '10.9.8.31', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible- tmp-1396233547.35-182235573044157 && chmod a+rx $HOME/.ansible/tmp /ansible-tmp-1396233547.35-182235573044157 && echo $HOME/.ansible/tmp/ansible-tmp-1396233547.35-182235573044157'"] <10.9.8.31> PUT /var/folders/n4/8skjkv9s5hbc4t5r0tr0xrk80000gn/T/tmpT1Vh6e TO /home/plyons/.ansible/tmp/ansible- tmp-1396233547.35-182235573044157/stat <10.9.8.31> EXEC ['ssh', '-C', '-tt', '-q', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/Users/plyons/.ansible/cp /ansible-ssh-%h-%p-%r', '-o', 'StrictHostKeyChecking=no', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications =gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'ConnectTimeout=10', '10.9.8.31', '/bin/sh -c \'sudo -k && sudo -H -S -p "[sudo via ansible, key=hyplatqjmvybpfqtukjegkibbuyrnoqj] password: " -u root /bin/sh -c \'"\'"\'echo SUDO-SUCCESS- hyplatqjmvybpfqtukjegkibbuyrnoqj; /usr/bin/python /home/plyons/.ansible/tmp/ansible- tmp-1396233547.35-182235573044157/stat\'"\'"\'\''] ``` Here's my playbook task: ``` tasks: - name: install ansible prerequisites script: ansible_prereqs.sh creates=/root/.ansible_prereqs_installed ``` And that ansible_prereqs.sh script: ``` #!/bin/sh #install ansible prereqs manually or all apt-based ansible commands will fail # http://euphonious-intuition.com/2013/01/bootstrapping-a-cluster-with-ansible-debian-6-and-oracle-java-7/ apt-get update apt-get install -y python python-apt python-pycurl sshpass touch /root/.ansible_prereqs_installed ```

Original source