The goal is to create a Amazon instance from a script.
This works fine if I am logged in as the user account but not from cron.
I believe SSH authentication is the problem. I am specifing the key in the ansible-playbook command but still not working.
Cron calls a perl script:
-
-
-
-
- ec2-user /iusr/bin/perl /home/ec2-user/test.pl >> /home/ec2-user/out
-
-
-
Perl Script Sets Variables Like this:
my $AnsiblePath=‘/home/ec2-user/ansible’;
my $AnsiblePlaybook=‘/home/ec2-user/create.yml’;
my $AzServerKey=‘/home/ec2-user/.ssh/taz-use-key.pem’;
my $AnsibleInventory=‘/home/ec2-user/ansible_hosts’;
$ENV{AWS_ACCESS_KEY_ID}=“MyAccessKey”;
$ENV{AWS_SECRET_ACCESS_KEY}=“SecretKey”;
$ENV{ANSIBLE}=“$AnsiblePath”;
$ENV{PATH}=“$ENV{PATH}:$ENV{ANSIBLE}/bin”;
$ENV{PYTHONPATH}=“/home/ec2-user/ansible/lib:”;
$ENV{ANSIBLE_LIBRARY}=“$ENV{ANSIBLE}/library”;
$ENV{MANPATH}=“$ENV{ANSIBLE}/docs/man:”;
ansible-playbook $AnsiblePlaybook -i $AnsibleInventory --private-key=$AzServerKey
;
The Error I get is:
output is:
PLAY [provision instance] *****************************************************
GATHERING FACTS ***************************************************************
fatal: [127.0.0.1] => {‘msg’: ‘FAILED: argument must be an int, or have a fileno() method.’, ‘failed’: True}
TASK: [Launch new EC2 instance] ***********************************************
FATAL: no hosts matched or all hosts have already failed – aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/var/tmp/ansible/create.retry