Where is the syntax error in ansible-playbook? - syntax

I'm facing some (silly) problems with ansible-playbook. I don't understand the error due to is a syntax-error but another similar playbook has been executed successfully and this one not.
ERROR! 'copy' is not a valid attribute for a Play
The error appears to have been in '/home/manu/monitorizacion/node-exporter/playbooks/deploy-node-exporter.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: Upload project directory to '{{ docker_home }}'
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
The thing is that i have a (install.yml) playbook with 2 include_tasks
---
- hosts: wargame
vars:
project_home: ../../node-exporter/
scripts_dir: /home/docker/node-exporter/textfile-collector/
docker_home: /home/docker/node-exporter/
tasks:
- include_tasks: packages.yml
- include_tasks: deploy-node-exporter.yml
packages.yml is fine and it is executed without problem
---
- name: Instalar paquetes requeridos para Docker e instalación
apt:
update_cache: true
name: "{{ packages }}"
vars:
packages:
- lsb-core
- apt-transport-https
- ca-certificates
- curl
- gnupg2
- python-setuptools
- python-pip
- git
- smartmontools
- name: Instalar clave Docker
apt_key:
url: https://download.docker.com/linux/debian/gpg
- name: Instalar repositorio Docker
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/debian {{ ansible_lsb.codename }} stable"
- name: Actualizar listado de paquetes
apt:
update_cache: yes
- name: Instalar Docker
apt:
name: docker-ce
- name: Instalar Docker-compose
pip:
name: docker-compose
- name: Grupo docker
group:
name: docker
state: present
- name: Usuario docker
user:
name: docker
group: docker
As you can see, the last executed task is "Usuario docker"
ok: [188.166.52.222] => {"append": false, "changed": false, "comment": "", "group": 998, "home": "/home/docker", "move_home": false, "name": "docker", "shell": "", "state": "present", "uid": 1002}
TASK [include_tasks] *****************************************************************************************************************************
fatal: [188.166.52.222]: FAILED! => {"reason": "no action detected in task. This often indicates a misspelled module name, or incorrect module path.\n\nThe error appears to have been in '/home/manu/monitorizacion/node-exporter/playbooks/deploy-node-exporter.yml': line 24, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n mode: '0755'\n- name: Deploy node-exporter\n ^ here\n"}
And now the error is in deploy-node-exporter.yml but the syntax is the same as in install.yml
---
- name: Upload project directory to '{{ docker_home }}'
copy:
src: "{{ project_home }}"
dest: "{{ docker_home }}"
directory_mode: yes
follow: yes
owner: docker
group: docker
- name: Fix perms for dirs
file:
path: "{{ item }}"
state: touch
mode: '0755'
with_items:
- "{{ docker_home }}"
- "{{ docker_home }}/textfile-collector"
- "{{ docker_home }}/playbooks"
- name: Give exec perms to smartmon.sh
file:
path: "{{ scripts_dir }}/smartmon.sh"
state: touch
mode: '0755'
- name: Deploy node-exporter
docker_compose:
project_src: "{{ docker_home }}"
build: no
state: present
recreate: always
register: output
- name: Creates cron entry for smartmon.sh
cron:
name: Cron job for collecting smartctl stats
minute: "*/15"
user: root
job: "{{ scripts_dir }}/smartmon.sh > {{ scripts_dir }}/smartmon.prom"
Or I'm blind due to i'm not able to find the syntax error or i think is an ansible problem
My current installed version
ansible 2.7.7
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.7.3 (default, Apr 3 2019, 05:39:12) [GCC 8.3.0]
--- update ---
I've put it everything on a single file
---
- hosts: myServer
vars:
project_home: ../../node-exporter/
scripts_dir: /home/docker/node-exporter/textfile-collector/
docker_home: /home/docker/node-exporter/
tasks:
- name: Instalar paquetes requeridos para Docker e instalación
apt:
update_cache: true
name: "{{ packages }}"
vars:
packages:
- lsb-core
- apt-transport-https
- ca-certificates
- curl
- gnupg2
- python-setuptools
- python-pip
- git
- smartmontools
- name: Instalar clave Docker
apt_key:
url: https://download.docker.com/linux/debian/gpg
- name: Instalar repositorio Docker
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/debian {{ ansible_lsb.codename }} stable"
- name: Actualizar listado de paquetes
apt:
update_cache: yes
- name: Instalar Docker
apt:
name: docker-ce
- name: Instalar Docker-compose
pip:
name: docker-compose
- name: Grupo docker
group:
name: docker
state: present
- name: Usuario docker
user:
name: docker
group: docker
- name: Upload project directory to '{{ docker_home }}'
copy:
src: "../../node-exporter/"
dest: "/home/docker/node-exporter/"
directory_mode: yes
follow: yes
owner: docker
group: docker
- name: Fix perms for dirs
file:
path: "{{ item }}"
state: touch
mode: "0755"
with_items:
- "/home/docker/node-exporter/"
- "/home/docker/node-exporter/textfile-collector"
- "/home/docker/node-exporter/playbooks"
- name: Give exec perms to smartmon.sh
file:
path: "{{ scripts_dir }}/smartmon.sh"
state: touch
mode: "0755"
- name: Creating cron entry for smartmon.sh
cron:
name: Cron job for collecting smartctl stats
minute: "*/15"
user: root
job: "{{ scripts_dir }}/smartmon.sh > {{ scripts_dir }}/smartmon.prom"
In this file I've removed
- name: Deploying node-exporter
docker_compose:
project_src: "{{ docker_home }}"
build: no
state: present
recreate: always
register: output
And now it works (without this part of code)
┌─[root#hippi3c0w] - [~manu/monitorizacion/node-exporter/playbooks] - [sáb ago 31, 20:59]
└─[$] <git:(master*)> ansible-playbook install_new.yml --syntax-check
playbook: install_new.yml
But the problem comes back when i add this part to the yaml file, so the problem is without doubts following part
- name: Deploying node-exporter
docker_compose:
project_src: "{{ docker_home }}"
build: no
state: present
recreate: always
register: output
Do you know what could be the problem? Maybe docker_compose?
--- UPDATE ---
It was due to ansible version. 2.7 doesn't support docker_compose directive. Updated to 2.8.4 and now it works properly.
PLAY RECAP ***************************************************************************************************************************************
[MyIP] : ok=16 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
┌─[root#hippi3c0w] - [~manu/monitorizacion/node-exporter/playbooks] - [dom sep 01, 08:34]
└─[$] <git:(master*)> ansible --version; ansible-playbook install.yml --syntax-check
ansible 2.8.4
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.16+ (default, Jul 8 2019, 09:45:29) [GCC 8.3.0]
playbook: install.yml

Would you please be more specific about which error you want to solve.
This error?
- name: Upload project directory to '{{ docker_home }}'
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
Or That one?
ok: [188.166.52.222] => {"append": false, "changed": false, "comment": "", "group":
998, "home": "/home/docker", "move_home": false, "name": "docker", "shell": "",
"state": "present", "uid": 1002}
TASK [include_tasks]
fatal: [188.166.52.222]: FAILED! => {"reason": "no action detected in task. This
often indicates a misspelled module name, or incorrect module path.\n\nThe error
appears to have been in '/home/manu/monitorizacion/node-exporter/playbooks/deploy-
node-exporter.yml': line 24, column 3, but may\nbe elsewhere in the file depending
on the exact syntax problem.\n\nThe offending line appears to be:\n\n mode: '
0755'\n- name: Deploy node-exporter\n ^ here\n"}

JFYI
copy is possible in my ansible version
tasks:
- name: Test copy
copy:
src: "/home/manu/test"
dest: "/home/user"
follow: yes
owner: user
group: user
mode: 0755
└─[$] <git:(master*)> ansible-playbook test.yaml --syntax-check
playbook: test.yaml
┌─[root#hippi3c0w] - [~manu/monitorizacion/node-exporter/playbooks] - [sáb ago 31, 20:33]
└─[$] <git:(master*)> ansible-playbook test.yaml -u user -v
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected
PLAY [myserver] ***********************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************
ok: [myIP]
TASK [Test copy] *********************************************************************************************************************************
changed: [myIP] => {"changed": true, "checksum": "55ca6286e3e4f4fba5d0448333fa99fc5a404a73", "dest": "/home/user/test", "gid": 1001, "group": "user", "mode": "0755", "owner": "user", "path": "/home/user/test", "size": 3, "state": "file", "uid": 1001}
PLAY RECAP ***************************************************************************************************************************************
myIP : ok=2 changed=1 unreachable=0 failed=0

--- UPDATE ---
It was due to ansible version. 2.7 doesn't support docker_compose directive. Updated to 2.8.4 and now it works properly.
PLAY RECAP ***************************************************************************************************************************************
[MyIP] : ok=16 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
┌─[root#hippi3c0w] - [~manu/monitorizacion/node-exporter/playbooks] - [dom sep 01, 08:34]
└─[$] <git:(master*)> ansible --version; ansible-playbook install.yml --syntax-check
ansible 2.8.4
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.16+ (default, Jul 8 2019, 09:45:29) [GCC 8.3.0]
playbook: install.yml

Related

Ansible JSON Query sabznbd Linux tarball only, not the whole source code

I am trying to download the latest version of sabnzbd from Github API via Ansible. I know how to get the whole tarball like so;
---
- name: Install sabnzbd
hosts: all
become: true
tasks:
- name: Get URL of latest sabnzbd
ansible.builtin.uri:
url: https://api.github.com/repos/sabnzbd/sabnzbd/releases/latest
body_format: json
return_content: true
remote_src: yes
register: json_reponse
- name: Download sabnzbd tarball
ansible.builtin.get_url:
url: "{{ json_reponse.json.tarball_url }}"
dest: /tmp
register: sabnzbd_tarball
However, I would rather just get the *src.tar.gz Linux tarball to keep the directory as clean as possible.
I have tried;
---
- name: Install sabnzbd
hosts: all
become: true
gather_facts: false
tasks:
- name: Get latest version
uri:
url: "https://api.github.com/repos/sabnzbd/sabnzbd/releases/latest"
return_content: yes
register: github_response
- set_fact:
binary_asset_url: "{{ github_response.json|json_query(query) }}"
vars:
query: "[? browser_download_url=='[*]]-src.tar.gz'"
- debug:
var: binary_asset_url
Just to see if I can get the URL, but I can't. I know I can use a shell one liner, but it's not as clean. I also would like to understand how to query json better by seeing this in action.
If you aren't stuck on using query you could just select the attribute using a search like this.
$ cat stack.yml
---
- name: Install sabnzbd
hosts:
localhost
tasks:
- name: Get URL of latest sabnzbd
ansible.builtin.uri:
url: https://api.github.com/repos/sabnzbd/sabnzbd/releases/latest
body_format: json
return_content: true
remote_src: yes
delegate_to: localhost
register: json_response
- name: Debug json_response
debug:
msg: "{{ (json_response.json.assets | selectattr('browser_download_url', 'search', 'src.tar.gz') | list | first).browser_download_url }}"
Yielding:
$ ansible-playbook stack.yml
PLAY [Install sabnzbd] *********************************************************************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************************************************************
ok: [localhost]
TASK [Get URL of latest sabnzbd] ***********************************************************************************************************************************************************
ok: [localhost]
TASK [Debug json_response] *****************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "https://github.com/sabnzbd/sabnzbd/releases/download/3.7.0/SABnzbd-3.7.0-src.tar.gz"
}

Ansible task failed with no error message

I'm using ansible and I get this:
PLAY [webservers-main]
********************************************************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [lxc-server]
TASK [include_vars] ***********************************************************************************************************************************************************************************************
ok: [lxc-server] => (item=/home/jredor/projets/webstore/architecture/provisioning/./distro-vars/Debian-9.yml)
TASK [set_fact] ***************************************************************************************************************************************************************************************************
ok: [lxc-server]
TASK [Disable Magento 2 Cron] *************************************************************************************************************************************************************************************
[WARNING]: Using world-readable permissions for temporary files Ansible needs to create when becoming an unprivileged user. This may be insecure. For information on securing this, see
https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user
fatal: [lxc-server]: FAILED! => {"changed": false, "failed": true, "msg": ""}
to retry, use: --limit #/home/jredor/projets/webstore/architecture/provisioning/install.retry
PLAY RECAP ********************************************************************************************************************************************************************************************************
lxc-server : ok=3 changed=0 unreachable=0 failed=1
I have an error but with no message. Since I'm new to ansible, I really don't know how to resolve it. I've followed the link that the warning provide, but it seems okay to me. Here is my install.yml:
---
- hosts: webservers-main
vars:
ansible_user: "{{ magento_project_user }}"
tasks:
- include: includes/include-vars.yml
- include: includes/cron-task.yml
vars:
magento_cron_disabled: true
- name: "Set permissions"
include: includes/permissions-tasks-light.yml
- name: "Set up env.php configuration file"
template:
src: "templates/magento/env_install.php.j2"
dest: "{{ magento_source_path }}/app/etc/env.php"
owner: "{{ magento_project_user }}"
group: "{{ magento_webserver_group }}"
mode: "u=rw,g=rw,o=r"
vars:
magento_cache_database: "{{ magento_cache_database_for_run }}"
- name: "Clear Magento DI and Generation (< 2.2)"
become: yes
become_method: sudo
become_user: "{{ magento_webserver_user }}"
shell: "rm -rf var/di/* var/generation/*"
args:
chdir: "{{ magento_source_path }}"
when: ( magento_version | version_compare('2.2.0', '<') )
- name: "Clear Magento DI and Generation (>= 2.2)"
become: yes
become_method: sudo
become_user: "{{ magento_webserver_user }}"
shell: "rm -rf generated/*"
args:
chdir: "{{ magento_source_path }}"
when: ( magento_version | version_compare('2.2.0', '>=') )
- name: "Install Magento 2"
become: yes
become_method: sudo
become_user: "{{ magento_webserver_user }}"
command: "{{ php_path}} {{ magento_source_path }}/bin/magento setup:install
--admin-firstname={{ magento_admin_firstname }}
--admin-lastname={{ magento_admin_lastname }}
--admin-email={{ magento_admin_email }}
--admin-user={{ magento_admin_user }}
--admin-password={{ magento_admin_password }}
--backend-frontname={{ magento_backend_frontname }}
--db-host={{ magento_db_host }}
--db-name={{ magento_db_name }}
--db-user={{ magento_db_user }}
--db-password={{ magento_db_password }}
--base-url=http://{{ magento_hostname }}/
--base-url-secure=https://{{ magento_hostname }}/
--use-secure={{ magento_secure_frontend }}
--use-secure-admin={{ magento_secure_backend }}
--use-rewrites={{ magento_use_rewrites }}
--currency={{ magento_currency }}
--language={{ magento_language }}
--timezone={{ magento_timezone }}
--cleanup-database
--magento-init-params=\"MAGE_MODE={{ magento_mode }}\"
-vvv"
args:
chdir: "{{ magento_source_path }}"
- include: includes/cron-task.yml
vars:
magento_cron_disabled: false
And this file includes cron-disable.yml, which is where the error is triggered:
- name: "Disable Magento 2 Cron"
become: yes
become_method: sudo
become_user: "{{ magento_webserver_user }}"
cron:
name: "Magento Cron Run"
minute: "*/1"
hour: "*"
job: "{{ magento_cronjob }}"
disabled: true
Could you help me with links or example to solve this? Thanks a lot

no package matching is available in ansible version 2.7.10

Can't install the packages in the virtual machine with ansible. Error: No package matching is available
---
- hosts: webservers
remote_user: root
#tasks:
# - name: test connection
# ping:
# remote_user: 192.168.33.10
#sudo: yes
tasks:
#- name: make sure apache is running
# service: name=httpd state=running
- name: General | Instalacion de paquetes requeridos.
action: apt pkg={{ item }} state=present
with_items:
-unzip
-mysql-server
-mysql-client
-apache2
-php-mysql
-php-apc
-php-xmlrpc
-php-soap
-php-gd
-php
-python-mysqldb
##
# Configuracion de Apache2
##
- name: Apache2 | Habilitar módulos
action: command a2enmod rewrite vhost_alias
##
# Reinicio de servicios
##
- name: Restart Apache
action: service name=apache2 state=restarted
Is there another option to do it, or how do I know what packages use', I tried installing a few packages at one, but failed too.
The complete error is:
PLAY [webservers] **************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.33.10]
TASK [General | Instalacion de paquetes requeridos.] ***************************
[DEPRECATION WARNING]: Invoking "apt" only once while using a loop via
squash_actions is deprecated. Instead of using a loop to supply multiple items
and specifying pkg: "{{ item }}", please use pkg: '-unzip -mysql-server
-mysql-client -apache2 -php-mysql -php-apc -php-xmlrpc -php-soap -php-gd -php
-python-mysqldb' and remove the loop. This feature will be removed in version
2.11. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
failed: [192.168.33.10] (item=[u'-unzip -mysql-server -mysql-client -apache2 -php-mysql -php-apc -php-xmlrpc -php-soap -php-gd -php -python-mysqldb']) => {"changed": false, "item": ["-unzip -mysql-server -mysql-client -apache2 -php-mysql -php-apc -php-xmlrpc -php-soap -php-gd -php -python-mysqldb"], "msg": "No package matching '-unzip -mysql-server -mysql-client -apache2 -php-mysql -php-apc -php-xmlrpc -php-soap -php-gd -php -python-mysqldb' is available"}
to retry, use: --limit #/home/guillermo/Documentos/vagrant-ansible/playbook.retry
PLAY RECAP *********************************************************************
192.168.33.10 : ok=1 changed=0 unreachable=0 failed=1
You have invalid YAML. A YAML list item is denoted by:
-<space><item>
Whereas you have:
-<item>
This is just a literal string. If you look at the error, you'll see the apt is trying to install packages with names like -unzip and -mysql-server, etc, which of course don't exist. You need to write your task like this:
- name: General | Instalacion de paquetes requeridos.
action: apt pkg={{ item }} state=present
with_items:
- unzip
- mysql-server
- mysql-client
- apache2
- php-mysql
- php-apc
- php-xmlrpc
- php-soap
- php-gd
- php
- python-mysqldb
But if you take another look at the error, you'll see:
Invoking "apt" only once while using a loop via squash_actions is deprecated...
It looks as if you've been learning Ansible based on outdated information. You should modernize your syntax to look like this:
- name: General | Instalacion de paquetes requeridos.
apt:
name: "{{ packages }}"
state: installed
vars:
packages:
- unzip
- mysql-server
- mysql-client
- apache2
- php-mysql
- php-apc
- php-xmlrpc
- php-soap
- php-gd
- php
- python-mysqldb

Calling an Ansible task in a parent role with different values

I've created two very simple Ansible roles called base and web. web is dependent on base and this dependency is defined in web/meta/main.yml.
base has the following task defined in base/tasks/main.yml:
- name: install required packages
apt:
name: "{{ install_packages }}"
update_cache: "{{ apt_update_cache }}"
cache_valid_time: "{{ apt_cache_valid_time }}"
The variables in base are defined in base/defaults/main.yml:
apt_update_cache: yes
apt_cache_valid_time: 3600
install_packages:
- ufw
- sshguard
The variables in web are defined in web/defaults/main.yml:
install_packages:
- nginx
What I want to do is:
Call install required packages from base, using the install_packages variable from base, and apt_update_cache and apt_cache_valid_time from base.
Call install required packages from web, using the install_packages variable from web, and apt_update_cache and apt_cache_valid_time from base (since I haven't overridden either of those two in web).
Is this possible, and if so how would I go about doing it? Alternatively, is there a 'better' way to achieve the same result, without reproducing the task in every dependent role (I'm likely to create several others which depend on base, and they will all have their own role-specific tasks too)?
Here's one option.
For clarity, rename install_packages in roles/base/defaults/main.yml to base_packages:
---
base_packages:
- ufw
- sshguard
Rewrite your package installation task in roles/base/main.yml so that it looks like this:
---
- name: install required packages
apt:
name: "{{ base_packages + extra_packages|default([]) }}"
update_cache: "{{ apt_update_cache }}"
cache_valid_time: "{{ apt_cache_valid_time }}"
In roles/web/defaults/main.yml, define web_packages:
---
web_packages:
- nginx
And in roles/web/meta/main.yml, declare your dependency like this:
---
dependencies:
- role: base
vars:
extra_packages: "{{ web_packages }}"
If I replace that apt task with a debug task:
- name: install required packages
debug:
msg:
apt:
name: "{{ base_packages + extra_packages|default([]) }}"
update_cache: "{{ apt_update_cache }}"
cache_valid_time: "{{ apt_cache_valid_time }}"
And use this playbook:
---
- hosts: localhost
gather_facts: false
roles:
- web
I get the following output:
PLAY [localhost] ******************************************************************************
TASK [base : install required packages] *******************************************************
ok: [localhost] => {
"msg": {
"apt": {
"cache_valid_time": 3600,
"name": [
"ufw",
"sshguard",
"nginx"
],
"update_cache": true
}
}
}
PLAY RECAP ************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0
As you can see, this installs both the packages declared in your base role as well as the packages from the web role.

basic telnet script to copy to flash drive

I am trying to use ansible to telnet into cisco switches and apply a copy startup-config disk0 command.
Ansible seems to never be able to pass
(?i)"Destination filename": "work please" through the expect command
---
- hosts: all
gather_facts: false
connection: local
tasks:
- name: telnet,login and execute command
ignore_errors: true
expect:
command: telnet "{{ inventory_hostname }}"
responses:
(?i)password: "{{ password}}"
(?i)#: copy startup-config disk0
(?i)"Destination filename": "{{ lookup('pipe','date') }"
echo: yes
register: telnet_output
What i am getting as an output
ansible-playbook 2.7.6
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /etc/ansible/ansible.cfg as config file
/var/lib/awx/projects/6500/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/var/lib/awx/projects/6500/hosts did not meet script requirements, check plugin documentation if this is unexpected
PLAYBOOK: copy-startup.yml *************************************************************************************************************************************************************************************************************
1 plays in copy-startup.yml
PLAY [all] *****************************************************************************************************************************************************************************************************************************
META: ran handlers
TASK [telnet,login and execute command] ************************************************************************************************************************************************************************************************
task path: /var/lib/awx/projects/6500/copy-startup.yml:6
fatal: [66.90.19.18]: FAILED! => {"changed": true, "cmd": "telnet \"66.90.19.18\"", "delta": "0:00:30.370396", "end": "2019-02-12 10:09:41.473716", "msg": "command exceeded timeout", "rc": null, "start": "2019-02-12 10:09:11.103320", "stdout": "Trying 66.90.19.18...\r\r\nConnected to 66.90.19.18.\r\r\nEscape character is '^]'.\r\r\n\r\n\r\nUser Access Verification\r\n\r\nPassword: \r\nLAB-6500-SUP2T#copy startup-config disk0\r\nDestination filename [disk0]? ", "stdout_lines": ["Trying 66.90.19.18...", "", "Connected to 66.90.19.18.", "", "Escape character is '^]'.", "", "", "", "User Access Verification", "", "Password: ", "LAB-6500-SUP2T#copy startup-config disk0", "Destination filename [disk0]? "]}
...ignoring
PLAY RECAP *****************************************************************************************************************************************************************************************************************************
66.90.19.18 : ok=2 changed=1 unreachable=0 failed=0
It seems to never want to write the Destination Filename[disk0]?
Any ideas
(?i)"Destination filename" matches for string with double quotes.
You need:
responses:
'(?i)password': "{{ password}}"
'(?i)#': copy startup-config disk0
'(?i)Destination filename': "{{ lookup('pipe','date') }"
---
- hosts: '6500'
gather_facts: true
connection: local
tasks:
- name: telnet,login and execute command
ignore_errors: true
expect:
command: telnet "{{ inventory_hostname }}"
responses:
(?i)Password: {{ password }}
(?i)Destination filename [disk0]? : "{{ lookup('pipe','date +%Y-%m-%d-%H-%M') }} {{ inventory_hostname }}"
(?i)#: copy startup-config disk0
(?i){{COMMAND}}: exit
echo: yes
register: telnet_output
This seems to be the best solution to what I need. I changed the order of operations and it was rocking,

Resources